Class IndexedFacetDistance
- java.lang.Object
-
- org.locationtech.jts.operation.distance.IndexedFacetDistance
-
public class IndexedFacetDistance extends java.lang.Object
Computes the distance between the facets (segments and vertices) of twoGeometry
s using a Branch-and-Bound algorithm. The Branch-and-Bound algorithm operates over a traversal of R-trees built on the target and the query geometries.This approach provides the following benefits:
- Performance is dramatically improved due to the use of the R-tree index and the pruning due to the Branch-and-Bound approach
- The spatial index on the target geometry is cached which allow reuse in an repeated query situation.
Geometry.distance(Geometry)
when one or both input geometries are large, or when evaluating many distance computations against a single geometry.This class is thread-safe.
- Author:
- Martin Davis
-
-
Constructor Summary
Constructors Constructor Description IndexedFacetDistance(Geometry g1)
Creates a new distance-finding instance for a given targetGeometry
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description double
distance(Geometry g)
Computes the distance from the base geometry to the given geometry.static double
distance(Geometry g1, Geometry g2)
Computes the distance between two geometries using the indexed approach.GeometryLocation[]
nearestLocations(Geometry g)
Computes the nearest locations on the base geometry and the given geometry.Coordinate[]
nearestPoints(Geometry g)
Compute the nearest locations on the target geometry and the given geometry.static Coordinate[]
nearestPoints(Geometry g1, Geometry g2)
Computes the nearest points on two geometries.
-
-
-
Constructor Detail
-
IndexedFacetDistance
public IndexedFacetDistance(Geometry g1)
Creates a new distance-finding instance for a given targetGeometry
.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
andPuntal
inputs, this is equivalent to computing the conventional distance. In the case ofPolygonal
inputs, this is equivalent to computing the distance to the polygon 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 geometryg2
- a geometry- Returns:
- the distance between the two geometries
-
nearestPoints
public static Coordinate[] nearestPoints(Geometry g1, Geometry g2)
Computes the nearest points on two geometries.- Parameters:
g1
- a geometryg2
- a geometry- Returns:
- the nearest points on the two geometries
-
distance
public double distance(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
-
nearestLocations
public GeometryLocation[] nearestLocations(Geometry g)
Computes the nearest locations on the base geometry and the given geometry.- Parameters:
g
- the geometry to compute the nearest location to- Returns:
- the nearest locations
-
nearestPoints
public Coordinate[] nearestPoints(Geometry g)
Compute the nearest locations on the target geometry and the given geometry.- Parameters:
g
- the geometry to compute the nearest point to- Returns:
- the nearest points
-
-