Class PointDistanceIndex
Coordinates) to the nearest
indexed distance target extracted from one or two input geometries, using a
spatial index for fast repeated queries.
Distance targets are extracted as:
- Linear components (
LineStrings), indexed as polyline facets, and - Point components (
Points), indexed as singleton targets.
The indexed linear items are not individual segments; instead, each
LineString is partitioned into contiguous “facets” (polyline chunks)
consisting of N coordinates (and therefore N-1 segments).
Each facet is inserted into an HPRtree using its envelope, and
nearest-facet search is refined by an exact point-to-segment distance
computation. This reduces index item count compared to segment-level indexing
while keeping good query speed.
Point items are indexed as singleton facets and participate in nearest-distance queries, but do not affect signed-distance classification.
Signed vs unsigned distance
- If a polygonal
boundaryis provided and aPointOnGeometryLocatoris enabled,distance(Coordinate)returns a signed distance: negative for points in theLocation.EXTERIORof the sign geometry, and positive/zero forLocation.INTERIOR/Location.BOUNDARY. unsignedDistance(Coordinate)always returns a non-negative distance.
Inputs
boundary: must bePolygonal(Polygon/MultiPolygon) or aLinearRing. Its linear components are used as distance targets (e.g., polygon rings). Additionally, it may be used to determine the sign ofdistance(Coordinate).obstacles: may be anyGeometry. Its linear components (LineStrings) and point components (Points/MultiPoints) are extracted and used as distance targets.
boundary or obstacles may be null, but not
both.- Author:
- Michael Carleton
-
Constructor Summary
ConstructorsConstructorDescriptionPointDistanceIndex(org.locationtech.jts.geom.Geometry boundary) Constructs an index using only a boundary geometry.PointDistanceIndex(org.locationtech.jts.geom.Geometry boundary, org.locationtech.jts.algorithm.locate.PointOnGeometryLocator boundaryLocator, org.locationtech.jts.geom.Geometry obstacles, int facetCoordCount) Constructs an index with an explicitly supplied boundary locator.PointDistanceIndex(org.locationtech.jts.geom.Geometry boundary, org.locationtech.jts.geom.Geometry obstacles) Constructs an index from a boundary and an obstacles geometry.PointDistanceIndex(org.locationtech.jts.geom.Geometry boundary, org.locationtech.jts.geom.Geometry obstacles, int facetCoordCount) Constructs an index from a boundary and/or obstacles geometry, using an explicit facet size. -
Method Summary
Modifier and TypeMethodDescriptiondoubledistance(double x, double y) Convenience overload ofdistance(Coordinate).doubledistance(org.locationtech.jts.geom.Coordinate p) Returns the (optionally) signed distance from the query coordinate to the nearest indexed linear component.doubleunsignedDistance(double x, double y) Convenience overload ofunsignedDistance(Coordinate).doubleunsignedDistance(org.locationtech.jts.geom.Coordinate p) Returns the non-negative distance from the query coordinate to the nearest indexed linear component.
-
Constructor Details
-
PointDistanceIndex
public PointDistanceIndex(org.locationtech.jts.geom.Geometry boundary) Constructs an index using only a boundary geometry.If
boundaryis non-null, signed distance is enabled using anYStripesPointInAreaLocator. Facet size defaults to 8 coordinates.- Parameters:
boundary- polygonal boundary used both as a distance target (via its rings) and to determine the sign ofdistance(Coordinate)- Throws:
IllegalArgumentException- ifboundaryis non-polygonal
-
PointDistanceIndex
public PointDistanceIndex(org.locationtech.jts.geom.Geometry boundary, org.locationtech.jts.geom.Geometry obstacles) Constructs an index from a boundary and an obstacles geometry.If
boundaryis non-null, signed distance is enabled using anYStripesPointInAreaLocator. Facet size defaults to 8 coordinates.- Parameters:
boundary- polygonal boundary used for distance targets and (optionally) signobstacles- any geometry; only linear components are used as distance targets- Throws:
IllegalArgumentException- if both inputs arenullIllegalArgumentException- ifboundaryis non-polygonal
-
PointDistanceIndex
public PointDistanceIndex(org.locationtech.jts.geom.Geometry boundary, org.locationtech.jts.geom.Geometry obstacles, int facetCoordCount) Constructs an index from a boundary and/or obstacles geometry, using an explicit facet size.If
boundaryis non-null, signed distance is enabled using anYStripesPointInAreaLocator.- Parameters:
boundary- polygonal boundary used for distance targets and (optionally) signobstacles- any geometry; only linear components are used as distance targetsfacetCoordCount- number of coordinates per facet (must be>= 2)- Throws:
IllegalArgumentException- if both inputs arenullIllegalArgumentException- ifboundaryis non-polygonalIllegalArgumentException- iffacetCoordCount < 2
-
PointDistanceIndex
public PointDistanceIndex(org.locationtech.jts.geom.Geometry boundary, org.locationtech.jts.algorithm.locate.PointOnGeometryLocator boundaryLocator, org.locationtech.jts.geom.Geometry obstacles, int facetCoordCount) Constructs an index with an explicitly supplied boundary locator.Passing a null
boundaryLocatordisables signed distance even ifboundaryis non-null, causingdistance(Coordinate)to behave likeunsignedDistance(Coordinate).- Parameters:
boundary- polygonal boundary used for distance targets and (optionally) signboundaryLocator- locator used to compute sign; may be null to disable signed distanceobstacles- any geometry; only linear components are used as distance targetsfacetCoordCount- number of coordinates per facet (must be>= 2)- Throws:
IllegalArgumentException- if both inputs arenullIllegalArgumentException- ifboundaryis non-polygonalIllegalArgumentException- iffacetCoordCount < 2
-
-
Method Details
-
distance
public double distance(org.locationtech.jts.geom.Coordinate p) Returns the (optionally) signed distance from the query coordinate to the nearest indexed linear component.- If
boundaryLocatoris present: negative means the point is outside the boundary. - If
boundaryLocatoris absent: this equalsunsignedDistance(Coordinate).
- Parameters:
p- query coordinate- Returns:
- signed distance, unsigned distance, or
Double.NaNif no facets exist
- If
-
distance
public double distance(double x, double y) Convenience overload ofdistance(Coordinate).- Parameters:
x- query xy- query y- Returns:
- signed distance, unsigned distance, or
Double.NaNif no facets exist
-
unsignedDistance
public double unsignedDistance(org.locationtech.jts.geom.Coordinate p) Returns the non-negative distance from the query coordinate to the nearest indexed linear component.This method uses the spatial index nearest-neighbour search and then computes the exact distance to segments within the chosen facet.
- Parameters:
p- query coordinate- Returns:
- distance
>= 0, orDouble.NaNif no facets exist
-
unsignedDistance
public double unsignedDistance(double x, double y) Convenience overload ofunsignedDistance(Coordinate).- Parameters:
x- query xy- query y- Returns:
- distance
>= 0, orDouble.NaNif no facets exist
-