Class LinearIterator
java.lang.Object
org.locationtech.jts.linearref.LinearIterator
An iterator over the components and coordinates of a linear geometry
(
LineStrings and MultiLineStrings.
The standard usage pattern for a LinearIterator is:
for (LinearIterator it = new LinearIterator(...); it.hasNext(); it.next()) {
...
int ci = it.getComponentIndex(); // for example
int vi = it.getVertexIndex(); // for example
...
}
- Version:
- 1.7
-
Constructor Summary
ConstructorsConstructorDescriptionLinearIterator(Geometry linear) Creates an iterator initialized to the start of a linearGeometryLinearIterator(Geometry linearGeom, int componentIndex, int vertexIndex) Creates an iterator starting at a specified component and vertex in a linearGeometryLinearIterator(Geometry linear, LinearLocation start) Creates an iterator starting at aLinearLocationon a linearGeometry -
Method Summary
Modifier and TypeMethodDescriptionintThe component index of the vertex the iterator is currently at.getLine()Gets theLineStringcomponent the iterator is current at.Gets the secondCoordinateof the current segment.Gets the firstCoordinateof the current segment.intThe vertex index of the vertex the iterator is currently at.booleanhasNext()Tests whether there are any vertices left to iterator over.booleanChecks whether the iterator cursor is pointing to the endpoint of a componentLineString.voidnext()Moves the iterator ahead to the next vertex and (possibly) linear component.
-
Constructor Details
-
LinearIterator
Creates an iterator initialized to the start of a linearGeometry- Parameters:
linear- the linear geometry to iterate over- Throws:
IllegalArgumentException- if linearGeom is not lineal
-
LinearIterator
Creates an iterator starting at aLinearLocationon a linearGeometry- Parameters:
linear- the linear geometry to iterate overstart- the location to start at- Throws:
IllegalArgumentException- if linearGeom is not lineal
-
LinearIterator
Creates an iterator starting at a specified component and vertex in a linearGeometry- Parameters:
linearGeom- the linear geometry to iterate overcomponentIndex- the component to start atvertexIndex- the vertex to start at- Throws:
IllegalArgumentException- if linearGeom is not lineal
-
-
Method Details
-
hasNext
public boolean hasNext()Tests whether there are any vertices left to iterator over. Specifically, hasNext() return true if the current state of the iterator represents a valid location on the linear geometry.- Returns:
trueif there are more vertices to scan
-
next
public void next()Moves the iterator ahead to the next vertex and (possibly) linear component. -
isEndOfLine
public boolean isEndOfLine()Checks whether the iterator cursor is pointing to the endpoint of a componentLineString.- Returns:
trueif the iterator is at an endpoint
-
getComponentIndex
public int getComponentIndex()The component index of the vertex the iterator is currently at.- Returns:
- the current component index
-
getVertexIndex
public int getVertexIndex()The vertex index of the vertex the iterator is currently at.- Returns:
- the current vertex index
-
getLine
Gets theLineStringcomponent the iterator is current at.- Returns:
- a linestring
-
getSegmentStart
Gets the firstCoordinateof the current segment. (the coordinate of the current vertex).- Returns:
- a
Coordinate
-
getSegmentEnd
Gets the secondCoordinateof the current segment. (the coordinate of the next vertex). If the iterator is at the end of a line,nullis returned.- Returns:
- a
Coordinateornull
-