Package com.github.micycle1.geoblitz
Class IndexedLengthIndexedLine
java.lang.Object
com.github.micycle1.geoblitz.IndexedLengthIndexedLine
IndexedLengthIndexedLine provides length-based linear-referencing using a
prebuilt cumulative-length index so that length→location queries are answered
in O(log n) time.
In contrast, the vanilla LengthIndexedLine locates positions by
scanning segments on each query (linear time), so this class is faster for
repeated queries on large geometries.
When to prefer this class
- Use
IndexedLengthIndexedLinewhen you have a large linear geometry and perform many length-based queries (extractPoint, extractLine, etc.). - Use the vanilla
LengthIndexedLinewhen queries are infrequent or when minimizing memory overhead is paramount.
Caveats
- Components are treated in geometry order (as with
LengthIndexedLine); they need not be spatially contiguous. - The class preserves the endpoint-resolution and degenerate-segment
handling of
LengthLocationMap; care is taken for zero-length segments/components.
- Author:
- Michael Carleton
-
Constructor Summary
ConstructorsConstructorDescriptionIndexedLengthIndexedLine(org.locationtech.jts.geom.Geometry linearGeom) Constructs an index for the supplied linear geometry. -
Method Summary
Modifier and TypeMethodDescriptiondoubleclampIndex(double index) org.locationtech.jts.geom.GeometryextractLine(double startIndex, double endIndex) Extracts the subline between two length indices.org.locationtech.jts.geom.CoordinateextractPoint(double index) Computes theCoordinatefor the point on the line at the given length index.org.locationtech.jts.geom.CoordinateextractPoint(double index, double offsetDistance) Computes theCoordinatefor the point on the line at the given length index, offset laterally by the supplied distance.doubledoublebooleanisValidIndex(double index)
-
Constructor Details
-
IndexedLengthIndexedLine
public IndexedLengthIndexedLine(org.locationtech.jts.geom.Geometry linearGeom) Constructs an index for the supplied linear geometry.The index is typically built once and used for many queries.
- Parameters:
linearGeom- the linearGeometry(LineString or MultiLineString)
-
-
Method Details
-
extractPoint
public org.locationtech.jts.geom.Coordinate extractPoint(double index) Computes theCoordinatefor the point on the line at the given length index.Negative indices are interpreted as measured from the end of the geometry. Out-of-range values are clamped to the line endpoints.
- Parameters:
index- the length index along the line- Returns:
- the coordinate at the given index
-
extractPoint
public org.locationtech.jts.geom.Coordinate extractPoint(double index, double offsetDistance) Computes theCoordinatefor the point on the line at the given length index, offset laterally by the supplied distance.A positive
offsetDistanceoffsets the point to the left of the oriented segment, negative to the right.- Parameters:
index- the length index along the lineoffsetDistance- lateral offset distance- Returns:
- the offset coordinate
-
extractLine
public org.locationtech.jts.geom.Geometry extractLine(double startIndex, double endIndex) Extracts the subline between two length indices.If
endIndex < startIndexthe returned geometry has reversed orientation. Indices are clamped to the valid range.- Parameters:
startIndex- start length indexendIndex- end length index- Returns:
- a linear
Geometryrepresenting the subline
-
getStartIndex
public double getStartIndex() -
getEndIndex
public double getEndIndex() -
isValidIndex
public boolean isValidIndex(double index) -
clampIndex
public double clampIndex(double index)
-