Class IndexedFacetDistance


  • public class IndexedFacetDistance
    extends java.lang.Object
    Computes the distance between the facets (segments and vertices) of two Geometrys using a Branch-and-Bound algorithm. The Branch-and-Bound algorithm operates over a traversal of R-trees built on the target and possibly also the query geometries.

    This approach provides the following benefits:

    • Performance is improved due to the effects of the R-tree index and the pruning due to the Branch-and-Bound approach
    • The spatial index on the target geometry can be cached to allow reuse in an incremental query situation.
    Using this technique can be much more performant than using getDistance(Geometry) when one or both input geometries are large, or when evaluating many distance computations against a single geometry.

    This class is not thread-safe.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  IndexedFacetDistance.FacetSequenceDistance
      Tests whether the base geometry lies within a specified distance of the given geometry.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private STRtree cachedTree  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static double distance​(Geometry g1, Geometry g2)
      Computes the distance between two geometries using the indexed approach.
      private static double facetDistance​(java.lang.Object[] obj)  
      double getDistance​(Geometry g)
      Computes the distance from the base geometry to the given geometry.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • cachedTree

        private STRtree cachedTree
    • Constructor Detail

      • IndexedFacetDistance

        public IndexedFacetDistance​(Geometry g1)
        Creates a new distance-finding instance for a given target Geometry.

        Distances will be computed to all facets of the input geometry. The facets of the geometry are the discrete segments and points contained in its components. In the case of Lineal and Puntal inputs, this is equivalent to computing the conventional distance. In the case of Polygonal inputs, this is equivalent to computing the distance to the polygons boundaries.

        Parameters:
        g1 - a Geometry, which may be of any type.
    • Method Detail

      • distance

        public static double distance​(Geometry g1,
                                      Geometry g2)
        Computes the distance between two geometries using the indexed approach.

        For geometries with many segments or points, this can be faster than using a simple distance algorithm.

        Parameters:
        g1 - a geometry
        g2 - a geometry
        Returns:
        the distance between the two geometries
      • getDistance

        public double getDistance​(Geometry g)
        Computes the distance from the base geometry to the given geometry.
        Parameters:
        g - the geometry to compute the distance to
        Returns:
        the computed distance
      • facetDistance

        private static double facetDistance​(java.lang.Object[] obj)