Package org.locationtech.jts.linearref
Class LinearLocation
- java.lang.Object
-
- org.locationtech.jts.linearref.LinearLocation
-
- All Implemented Interfaces:
java.lang.Comparable
public class LinearLocation extends java.lang.Object implements java.lang.Comparable
Represents a location along aLineString
orMultiLineString
. The referenced geometry is not maintained within this location, but must be provided for operations which require it. Various methods are provided to manipulate the location value and query the geometry it references.
-
-
Constructor Summary
Constructors Constructor Description LinearLocation()
Creates a location referring to the start of a linear geometryLinearLocation(int segmentIndex, double segmentFraction)
LinearLocation(int componentIndex, int segmentIndex, double segmentFraction)
LinearLocation(LinearLocation loc)
Creates a new location equal to a given one.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
clamp(Geometry linear)
Ensures the indexes are valid for a given linearGeometry
.java.lang.Object
clone()
Deprecated.int
compareLocationValues(int componentIndex1, int segmentIndex1, double segmentFraction1)
Compares this object with the specified index values for order.static int
compareLocationValues(int componentIndex0, int segmentIndex0, double segmentFraction0, int componentIndex1, int segmentIndex1, double segmentFraction1)
Compares two sets of location values for order.int
compareTo(java.lang.Object o)
Compares this object with the specified object for order.LinearLocation
copy()
Copies this locationint
getComponentIndex()
Gets the component index for this location.Coordinate
getCoordinate(Geometry linearGeom)
Gets theCoordinate
along the given linearGeometry
which is referenced by this location.static LinearLocation
getEndLocation(Geometry linear)
Gets a location which refers to the end of a linearGeometry
.LineSegment
getSegment(Geometry linearGeom)
Gets aLineSegment
representing the segment of the given linearGeometry
which contains this location.double
getSegmentFraction()
Gets the segment fraction for this locationint
getSegmentIndex()
Gets the segment index for this locationdouble
getSegmentLength(Geometry linearGeom)
Gets the length of the segment in the given Geometry containing this location.boolean
isEndpoint(Geometry linearGeom)
Tests whether this location is an endpoint of the linear component it refers to.boolean
isOnSameSegment(LinearLocation loc)
Tests whether two locations are on the same segment in the parentGeometry
.boolean
isValid(Geometry linearGeom)
Tests whether this location refers to a valid location on the given linearGeometry
.boolean
isVertex()
Tests whether this location refers to a vertexstatic Coordinate
pointAlongSegmentByFraction(Coordinate p0, Coordinate p1, double frac)
Computes theCoordinate
of a point a given fraction along the line segment (p0, p1).void
setToEnd(Geometry linear)
Sets the value of this location to refer to the end of a linear geometry.void
snapToVertex(Geometry linearGeom, double minDistance)
Snaps the value of this location to the nearest vertex on the given linearGeometry
, if the vertex is closer than minDistance.LinearLocation
toLowest(Geometry linearGeom)
Converts a linear location to the lowest equivalent location index.java.lang.String
toString()
-
-
-
Constructor Detail
-
LinearLocation
public LinearLocation()
Creates a location referring to the start of a linear geometry
-
LinearLocation
public LinearLocation(int segmentIndex, double segmentFraction)
-
LinearLocation
public LinearLocation(int componentIndex, int segmentIndex, double segmentFraction)
-
LinearLocation
public LinearLocation(LinearLocation loc)
Creates a new location equal to a given one.- Parameters:
loc
- a LinearLocation
-
-
Method Detail
-
getEndLocation
public static LinearLocation getEndLocation(Geometry linear)
Gets a location which refers to the end of a linearGeometry
.- Parameters:
linear
- the linear geometry- Returns:
- a new LinearLocation
-
pointAlongSegmentByFraction
public static Coordinate pointAlongSegmentByFraction(Coordinate p0, Coordinate p1, double frac)
Computes theCoordinate
of a point a given fraction along the line segment (p0, p1). If the fraction is greater than 1.0 the last point of the segment is returned. If the fraction is less than or equal to 0.0 the first point of the segment is returned. The Z ordinate is interpolated from the Z-ordinates of the given points, if they are specified.- Parameters:
p0
- the first point of the line segmentp1
- the last point of the line segmentfrac
- the length to the desired point- Returns:
- the Coordinate of the desired point
-
clamp
public void clamp(Geometry linear)
Ensures the indexes are valid for a given linearGeometry
.- Parameters:
linear
- a linear geometry
-
snapToVertex
public void snapToVertex(Geometry linearGeom, double minDistance)
Snaps the value of this location to the nearest vertex on the given linearGeometry
, if the vertex is closer than minDistance.- Parameters:
linearGeom
- a linear geometryminDistance
- the minimum allowable distance to a vertex
-
getSegmentLength
public double getSegmentLength(Geometry linearGeom)
Gets the length of the segment in the given Geometry containing this location.- Parameters:
linearGeom
- a linear geometry- Returns:
- the length of the segment
-
setToEnd
public void setToEnd(Geometry linear)
Sets the value of this location to refer to the end of a linear geometry.- Parameters:
linear
- the linear geometry to use to set the end
-
getComponentIndex
public int getComponentIndex()
Gets the component index for this location.- Returns:
- the component index
-
getSegmentIndex
public int getSegmentIndex()
Gets the segment index for this location- Returns:
- the segment index
-
getSegmentFraction
public double getSegmentFraction()
Gets the segment fraction for this location- Returns:
- the segment fraction
-
isVertex
public boolean isVertex()
Tests whether this location refers to a vertex- Returns:
- true if the location is a vertex
-
getCoordinate
public Coordinate getCoordinate(Geometry linearGeom)
Gets theCoordinate
along the given linearGeometry
which is referenced by this location.- Parameters:
linearGeom
- the linear geometry referenced by this location- Returns:
- the Coordinate at the location
-
getSegment
public LineSegment getSegment(Geometry linearGeom)
Gets aLineSegment
representing the segment of the given linearGeometry
which contains this location.- Parameters:
linearGeom
- a linear geometry- Returns:
- the LineSegment containing the location
-
isValid
public boolean isValid(Geometry linearGeom)
Tests whether this location refers to a valid location on the given linearGeometry
.- Parameters:
linearGeom
- a linear geometry- Returns:
- true if this location is valid
-
compareTo
public int compareTo(java.lang.Object o)
Compares this object with the specified object for order.- Specified by:
compareTo
in interfacejava.lang.Comparable
- Parameters:
o
- theLineStringLocation
with which thisCoordinate
is being compared- Returns:
- a negative integer, zero, or a positive integer as this
LineStringLocation
is less than, equal to, or greater than the specifiedLineStringLocation
-
compareLocationValues
public int compareLocationValues(int componentIndex1, int segmentIndex1, double segmentFraction1)
Compares this object with the specified index values for order.- Parameters:
componentIndex1
- a component indexsegmentIndex1
- a segment indexsegmentFraction1
- a segment fraction- Returns:
- a negative integer, zero, or a positive integer as this
LineStringLocation
is less than, equal to, or greater than the specified locationValues
-
compareLocationValues
public static int compareLocationValues(int componentIndex0, int segmentIndex0, double segmentFraction0, int componentIndex1, int segmentIndex1, double segmentFraction1)
Compares two sets of location values for order.- Parameters:
componentIndex0
- a component indexsegmentIndex0
- a segment indexsegmentFraction0
- a segment fractioncomponentIndex1
- another component indexsegmentIndex1
- another segment indexsegmentFraction1
- another segment fraction- Returns:
- a negative integer, zero, or a positive integer as the first set of location values is less than, equal to, or greater than the second set of locationValues
-
isOnSameSegment
public boolean isOnSameSegment(LinearLocation loc)
Tests whether two locations are on the same segment in the parentGeometry
.- Parameters:
loc
- a location on the same geometry- Returns:
- true if the locations are on the same segment of the parent geometry
-
isEndpoint
public boolean isEndpoint(Geometry linearGeom)
Tests whether this location is an endpoint of the linear component it refers to.- Parameters:
linearGeom
- the linear geometry referenced by this location- Returns:
- true if the location is a component endpoint
-
toLowest
public LinearLocation toLowest(Geometry linearGeom)
Converts a linear location to the lowest equivalent location index. The lowest index has the lowest possible component and segment indices.Specifically:
- if the location point is an endpoint, a location value is returned as (nseg-1, 1.0)
- if the location point is ambiguous (i.e. an endpoint and a startpoint), the lowest endpoint location is returned
- Parameters:
linearGeom
- the linear geometry referenced by this location- Returns:
- the lowest equivalent location
-
clone
public java.lang.Object clone()
Deprecated.Copies this location- Returns:
- a copy of this location
-
copy
public LinearLocation copy()
Copies this location- Returns:
- a copy of this location
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-