Class RTreeIndexedSpatialSet<V extends NFEGeoObject>

  • Type Parameters:
    V - The type of elements in the set. Any subclass of NFEGeoObject
    All Implemented Interfaces:
    java.lang.Iterable<V>, java.util.Collection<V>, java.util.Set<V>, IndexedSpatialSet<V>

    public class RTreeIndexedSpatialSet<V extends NFEGeoObject>
    extends java.lang.Object
    implements IndexedSpatialSet<V>
    An implementation of IndexedSpatialSet that uses an R-tree index and stores instances of NFEGeoObject.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(V geoObj)  
      boolean addAll​(java.util.Collection<? extends V> geoObjects)  
      void clear()  
      boolean contains​(java.lang.Object obj)  
      boolean containsAll​(java.util.Collection<?> geoObjects)  
      V get​(java.awt.geom.Point2D point, double tolerance)
      Gets the element which is closer to the given point but within the tolerance.
      V get​(java.lang.Object key)
      Gets the object identified by the given key
      java.util.Collection<V> getAll​(java.awt.geom.Point2D point, double tolerance)
      Gets all the elements which distance to the given point is within the tolerance
      java.util.Collection<V> getAnyInteract​(java.awt.geom.Area area)
      Gets all the elements interacting in some way with the given area
      java.util.Collection<V> getAnyInteract​(java.awt.geom.Rectangle2D mbr)
      Gets all the elements interacting in some way with the given rectangle
      protected double getDistance​(java.awt.geom.Point2D point1, java.awt.geom.Point2D point2)  
      protected java.util.Collection<V> getLines​(java.util.Collection<V> geoObjects, java.awt.geom.Point2D point, double tolerance)  
      protected double getMinDistanceToLine​(java.awt.geom.Point2D point, java.awt.geom.Point2D[] linePoints)  
      protected double getMinDistanceToMiltiPoint​(java.awt.geom.Point2D point, JGeometry multiPoint)  
      protected double getMinDistanceToMultiLine​(java.awt.geom.Point2D point, JGeometry line)
      Returns the distance between point and a line (or multiline) from the line segment closest to the point.
      protected V getNearestLine​(java.util.Collection<V> geoObjects, java.awt.geom.Point2D point, double tolerance)  
      protected V getNearestPoint​(java.util.Collection<V> geoObjects, java.awt.geom.Point2D point, double tolerance)  
      protected java.util.Collection<V> getPoints​(java.util.Collection<V> geoObjects, java.awt.geom.Point2D point, double tolerance)  
      AbstractSpatialIndex getSpatialindex()
      Gets the underlying implementation used to perform spatial-indexing
      boolean isEmpty()  
      boolean isGeometryTypeExpected​(int geometryType)
      Tells whether the set is expecting the specified geometry type (from JGeometry).
      java.util.Iterator<V> iterator()  
      boolean refreshIndex​(java.lang.Object key)
      Rebuilds the index associated to an object identified by the given key
      boolean remove​(java.lang.Object obj)  
      boolean removeAll​(java.util.Collection<?> geoObjects)  
      boolean retainAll​(java.util.Collection<?> arg0)  
      int size()  
      java.lang.Object[] toArray()  
      <T> T[] toArray​(T[] array)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        parallelStream, removeIf, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.Set

        equals, hashCode, spliterator
    • Field Detail

      • geoObjectMap

        protected java.util.Map<java.lang.Object,​V extends NFEGeoObject> geoObjectMap
      • geometryTypes

        protected java.util.Set<java.lang.Integer> geometryTypes
    • Constructor Detail

      • RTreeIndexedSpatialSet

        public RTreeIndexedSpatialSet()
      • RTreeIndexedSpatialSet

        public RTreeIndexedSpatialSet​(int[] expectedGeometryTypes)
        Creates an instance of RTreeIndexedSpatialSet
        Parameters:
        geometryTypes - A list of geometry types (from JGeometry) which will be expected to be contained in the set. By providing this values, spatial searches may be optimized since only geometries of the expected types will be looked.
    • Method Detail

      • add

        public boolean add​(V geoObj)
        Specified by:
        add in interface java.util.Collection<V extends NFEGeoObject>
        Specified by:
        add in interface java.util.Set<V extends NFEGeoObject>
      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<V extends NFEGeoObject>
        Specified by:
        size in interface java.util.Set<V extends NFEGeoObject>
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Collection<V extends NFEGeoObject>
        Specified by:
        isEmpty in interface java.util.Set<V extends NFEGeoObject>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Collection<V extends NFEGeoObject>
        Specified by:
        clear in interface java.util.Set<V extends NFEGeoObject>
      • refreshIndex

        public boolean refreshIndex​(java.lang.Object key)
        Description copied from interface: IndexedSpatialSet
        Rebuilds the index associated to an object identified by the given key
        Specified by:
        refreshIndex in interface IndexedSpatialSet<V extends NFEGeoObject>
        Parameters:
        key - an object's key
        Returns:
        true if the index could be refreshed
      • get

        public V get​(java.lang.Object key)
        Description copied from interface: IndexedSpatialSet
        Gets the object identified by the given key
        Specified by:
        get in interface IndexedSpatialSet<V extends NFEGeoObject>
        Parameters:
        key - an object's key
        Returns:
        the object associated to the key or null if no object is related to the key
      • get

        public V get​(java.awt.geom.Point2D point,
                     double tolerance)
        Description copied from interface: IndexedSpatialSet
        Gets the element which is closer to the given point but within the tolerance.
        Specified by:
        get in interface IndexedSpatialSet<V extends NFEGeoObject>
        Parameters:
        point - a spatial point
        tolerance - the maximum distance an element can be from the point to be selected
        Returns:
        the element closest to the given point with a distance equal or less to the tolerance
      • getAll

        public java.util.Collection<V> getAll​(java.awt.geom.Point2D point,
                                              double tolerance)
        Description copied from interface: IndexedSpatialSet
        Gets all the elements which distance to the given point is within the tolerance
        Specified by:
        getAll in interface IndexedSpatialSet<V extends NFEGeoObject>
        Parameters:
        point - a spatial point
        tolerance - tolerance the maximum distance an element can be from the point to be selected
        Returns:
        a collection containing all the elements which distance to the given point is within the tolerance
      • getAnyInteract

        public java.util.Collection<V> getAnyInteract​(java.awt.geom.Rectangle2D mbr)
        Description copied from interface: IndexedSpatialSet
        Gets all the elements interacting in some way with the given rectangle
        Specified by:
        getAnyInteract in interface IndexedSpatialSet<V extends NFEGeoObject>
        Parameters:
        mbr - a rectangle
        Returns:
        a collection containing all the elements interacting in some way with the given rectangle
      • getAnyInteract

        public java.util.Collection<V> getAnyInteract​(java.awt.geom.Area area)
        Description copied from interface: IndexedSpatialSet
        Gets all the elements interacting in some way with the given area
        Specified by:
        getAnyInteract in interface IndexedSpatialSet<V extends NFEGeoObject>
        Parameters:
        area - a java area
        Returns:
        a collection containing all the elements interacting in some way with the given area
      • addAll

        public boolean addAll​(java.util.Collection<? extends V> geoObjects)
        Specified by:
        addAll in interface java.util.Collection<V extends NFEGeoObject>
        Specified by:
        addAll in interface java.util.Set<V extends NFEGeoObject>
      • contains

        public boolean contains​(java.lang.Object obj)
        Specified by:
        contains in interface java.util.Collection<V extends NFEGeoObject>
        Specified by:
        contains in interface java.util.Set<V extends NFEGeoObject>
      • containsAll

        public boolean containsAll​(java.util.Collection<?> geoObjects)
        Specified by:
        containsAll in interface java.util.Collection<V extends NFEGeoObject>
        Specified by:
        containsAll in interface java.util.Set<V extends NFEGeoObject>
      • iterator

        public java.util.Iterator<V> iterator()
        Specified by:
        iterator in interface java.util.Collection<V extends NFEGeoObject>
        Specified by:
        iterator in interface java.lang.Iterable<V extends NFEGeoObject>
        Specified by:
        iterator in interface java.util.Set<V extends NFEGeoObject>
      • remove

        public boolean remove​(java.lang.Object obj)
        Specified by:
        remove in interface java.util.Collection<V extends NFEGeoObject>
        Specified by:
        remove in interface java.util.Set<V extends NFEGeoObject>
      • removeAll

        public boolean removeAll​(java.util.Collection<?> geoObjects)
        Specified by:
        removeAll in interface java.util.Collection<V extends NFEGeoObject>
        Specified by:
        removeAll in interface java.util.Set<V extends NFEGeoObject>
      • retainAll

        public boolean retainAll​(java.util.Collection<?> arg0)
        Specified by:
        retainAll in interface java.util.Collection<V extends NFEGeoObject>
        Specified by:
        retainAll in interface java.util.Set<V extends NFEGeoObject>
      • toArray

        public java.lang.Object[] toArray()
        Specified by:
        toArray in interface java.util.Collection<V extends NFEGeoObject>
        Specified by:
        toArray in interface java.util.Set<V extends NFEGeoObject>
      • toArray

        public <T> T[] toArray​(T[] array)
        Specified by:
        toArray in interface java.util.Collection<V extends NFEGeoObject>
        Specified by:
        toArray in interface java.util.Set<V extends NFEGeoObject>
      • isGeometryTypeExpected

        public boolean isGeometryTypeExpected​(int geometryType)
        Tells whether the set is expecting the specified geometry type (from JGeometry). If the set has no expected geometry types defined it will always return true for any type.
        Parameters:
        geometryType -
        Returns:
      • getPoints

        protected java.util.Collection<V> getPoints​(java.util.Collection<V> geoObjects,
                                                    java.awt.geom.Point2D point,
                                                    double tolerance)
      • getNearestPoint

        protected V getNearestPoint​(java.util.Collection<V> geoObjects,
                                    java.awt.geom.Point2D point,
                                    double tolerance)
      • getMinDistanceToMiltiPoint

        protected double getMinDistanceToMiltiPoint​(java.awt.geom.Point2D point,
                                                    JGeometry multiPoint)
      • getDistance

        protected double getDistance​(java.awt.geom.Point2D point1,
                                     java.awt.geom.Point2D point2)
      • getLines

        protected java.util.Collection<V> getLines​(java.util.Collection<V> geoObjects,
                                                   java.awt.geom.Point2D point,
                                                   double tolerance)
      • getNearestLine

        protected V getNearestLine​(java.util.Collection<V> geoObjects,
                                   java.awt.geom.Point2D point,
                                   double tolerance)
      • getMinDistanceToMultiLine

        protected double getMinDistanceToMultiLine​(java.awt.geom.Point2D point,
                                                   JGeometry line)
        Returns the distance between point and a line (or multiline) from the line segment closest to the point.
        Parameters:
        line - A geometry of type line or multiline
        point -
        Returns:
      • getMinDistanceToLine

        protected double getMinDistanceToLine​(java.awt.geom.Point2D point,
                                              java.awt.geom.Point2D[] linePoints)