getSegmentLength method

double getSegmentLength(
  1. Geometry linearGeom
)

Gets the length of the segment in the given Geometry containing this location.

@param linearGeom a linear geometry @return the length of the segment

Implementation

double getSegmentLength(Geometry linearGeom) {
  LineString lineComp = linearGeom.getGeometryN(componentIndex) as LineString;

  // ensure segment index is valid
  int segIndex = segmentIndex;
  if (segmentIndex >= numSegments(lineComp))
    segIndex = lineComp.getNumPoints() - 2;

  Coordinate p0 = lineComp.getCoordinateN(segIndex);
  Coordinate p1 = lineComp.getCoordinateN(segIndex + 1);
  return p0.distance(p1);
}