com.vividsolutions.jts.linearref

Class LengthIndexedLine


public class LengthIndexedLine
extends java.lang.Object

Supports linear referencing along a linear Geometry using the length along the line as the index. Negative length values are taken as measured in the reverse direction from the end of the geometry. Out-of-range index values are handled by clamping them to the valid range of values. Non-simple lines (i.e. which loop back to cross or touch themselves) are supported.

Constructor Summary

LengthIndexedLine(Geometry linearGeom)
Constructs an object which allows a linear Geometry to be linearly referenced using length as an index.

Method Summary

double
clampIndex(double index)
Computes a valid index for this line by clamping the given index to the valid range of index values
Geometry
extractLine(double startIndex, double endIndex)
Computes the LineString for the interval on the line between the given indices.
Coordinate
extractPoint(double index)
Computes the Coordinate for the point on the line at the given index.
double
getEndIndex()
Returns the index of the end of the line
double
getStartIndex()
Returns the index of the start of the line
double
indexOf(Coordinate pt)
Computes the minimum index for a point on the line.
double
indexOfAfter(Coordinate pt, double minIndex)
Finds the index for a point on the line which is greater than the given index.
double[]
indicesOf(Geometry subLine)
Computes the indices for a subline of the line.
boolean
isValidIndex(double index)
Tests whether an index is in the valid index range for the line.
double
project(Coordinate pt)
Computes the index for the closest point on the line to the given point.

Constructor Details

LengthIndexedLine

public LengthIndexedLine(Geometry linearGeom)
Constructs an object which allows a linear Geometry to be linearly referenced using length as an index.
Parameters:
linearGeom - the linear geometry to reference along

Method Details

clampIndex

public double clampIndex(double index)
Computes a valid index for this line by clamping the given index to the valid range of index values
Returns:
a valid index value

extractLine

public Geometry extractLine(double startIndex,
                            double endIndex)
Computes the LineString for the interval on the line between the given indices. If the endIndex lies before the startIndex, the computed geometry is reversed.
Parameters:
startIndex - the index of the start of the interval
endIndex - the index of the end of the interval
Returns:
the linear interval between the indices

extractPoint

public Coordinate extractPoint(double index)
Computes the Coordinate for the point on the line at the given index. If the index is out of range the first or last point on the line will be returned.
Parameters:
index - the index of the desired point
Returns:
the Coordinate at the given index

getEndIndex

public double getEndIndex()
Returns the index of the end of the line
Returns:
the end index

getStartIndex

public double getStartIndex()
Returns the index of the start of the line
Returns:
the start index

indexOf

public double indexOf(Coordinate pt)
Computes the minimum index for a point on the line. If the line is not simple (i.e. loops back on itself) a single point may have more than one possible index. In this case, the smallest index is returned. The supplied point does not necessarily have to lie precisely on the line, but if it is far from the line the accuracy and performance of this function is not guaranteed. Use project(Coordinate) to compute a guaranteed result for points which may be far from the line.
Parameters:
pt - a point on the line
Returns:
the minimum index of the point
See Also:
project

indexOfAfter

public double indexOfAfter(Coordinate pt,
                           double minIndex)
Finds the index for a point on the line which is greater than the given index. If no such index exists, returns minIndex. This method can be used to determine all indexes for a point which occurs more than once on a non-simple line. It can also be used to disambiguate cases where the given point lies slightly off the line and is equidistant from two different points on the line. The supplied point does not necessarily have to lie precisely on the line, but if it is far from the line the accuracy and performance of this function is not guaranteed. Use project(Coordinate) to compute a guaranteed result for points which may be far from the line.
Parameters:
pt - a point on the line
minIndex - the value the returned index must be greater than
Returns:
the index of the point greater than the given minimum index
See Also:
project

indicesOf

public double[] indicesOf(Geometry subLine)
Computes the indices for a subline of the line. (The subline must conform to the line; that is, all vertices in the subline (except possibly the first and last) must be vertices of the line and occcur in the same order).
Parameters:
subLine - a subLine of the line
Returns:
a pair of indices for the start and end of the subline.

isValidIndex

public boolean isValidIndex(double index)
Tests whether an index is in the valid index range for the line.
Parameters:
Returns:
true if the index is in the valid range

project

public double project(Coordinate pt)
Computes the index for the closest point on the line to the given point. If more than one point has the closest distance the first one along the line is returned. (The point does not necessarily have to lie precisely on the line.)
Parameters:
pt - a point on the line
Returns:
the index of the point