Class IndexedLengthIndexedLine

java.lang.Object
com.github.micycle1.geoblitz.IndexedLengthIndexedLine

public final class IndexedLengthIndexedLine extends Object
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 IndexedLengthIndexedLine when you have a large linear geometry and perform many length-based queries (extractPoint, extractLine, etc.).
  • Use the vanilla LengthIndexedLine when 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

    Constructors
    Constructor
    Description
    IndexedLengthIndexedLine(org.locationtech.jts.geom.Geometry linearGeom)
    Constructs an index for the supplied linear geometry.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    clampIndex(double index)
    Clamps the index to the valid range [0, totalLength].
    org.locationtech.jts.geom.Geometry
    extractLine(double startIndex, double endIndex)
    Extracts the subline between two length indices.
    org.locationtech.jts.geom.Coordinate
    extractPoint(double index)
    Computes the Coordinate for the point on the line at the given length index.
    org.locationtech.jts.geom.Coordinate
    extractPoint(double index, double offsetDistance)
    Computes the Coordinate for the point on the line at the given length index, offset laterally by the supplied distance.
    double
    Returns the end index of the line.
    double
    Returns the start index of the line.
    boolean
    isValidIndex(double index)
    Checks if the given index is valid (within the range of the line).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 linear Geometry (LineString or MultiLineString)
  • Method Details

    • extractPoint

      public org.locationtech.jts.geom.Coordinate extractPoint(double index)
      Computes the Coordinate for 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 the Coordinate for the point on the line at the given length index, offset laterally by the supplied distance.

      A positive offsetDistance offsets the point to the left of the oriented segment, negative to the right.

      Parameters:
      index - the length index along the line
      offsetDistance - 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 < startIndex the returned geometry has reversed orientation. Indices are clamped to the valid range.

      Parameters:
      startIndex - start length index
      endIndex - end length index
      Returns:
      a linear Geometry representing the subline
    • getStartIndex

      public double getStartIndex()
      Returns the start index of the line.
      Returns:
      the start index (0.0)
    • getEndIndex

      public double getEndIndex()
      Returns the end index of the line.
      Returns:
      the end index (total length)
    • isValidIndex

      public boolean isValidIndex(double index)
      Checks if the given index is valid (within the range of the line).
      Parameters:
      index - the index to check
      Returns:
      true if the index is valid
    • clampIndex

      public double clampIndex(double index)
      Clamps the index to the valid range [0, totalLength].
      Parameters:
      index - the index to clamp
      Returns:
      the clamped index