Class LineStringSnapper
java.lang.Object
org.locationtech.jts.operation.overlay.snap.LineStringSnapper
Snaps the vertices and segments of a
LineString
to a set of target snap vertices.
A snap distance tolerance is used to control where snapping is performed.
The implementation handles empty geometry and empty snap vertex sets.
- Version:
- 1.7
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private boolean
private LineSegment
private double
private Coordinate[]
-
Constructor Summary
ConstructorsConstructorDescriptionLineStringSnapper
(Coordinate[] srcPts, double snapTolerance) Creates a new snapper using the given points as source points to be snapped.LineStringSnapper
(LineString srcLine, double snapTolerance) Creates a new snapper using the points in the givenLineString
as source snap points. -
Method Summary
Modifier and TypeMethodDescriptionprivate int
findSegmentIndexToSnap
(Coordinate snapPt, CoordinateList srcCoords) Finds a src segment which snaps to (is close to) the given snap point.private Coordinate
findSnapForVertex
(Coordinate pt, Coordinate[] snapPts) private static boolean
isClosed
(Coordinate[] pts) void
setAllowSnappingToSourceVertices
(boolean allowSnappingToSourceVertices) private void
snapSegments
(CoordinateList srcCoords, Coordinate[] snapPts) Snap segments of the source to nearby snap vertices.snapTo
(Coordinate[] snapPts) Snaps the vertices and segments of the source LineString to the given set of snap vertices.private void
snapVertices
(CoordinateList srcCoords, Coordinate[] snapPts) Snap source vertices to vertices in the target.
-
Field Details
-
snapTolerance
private double snapTolerance -
srcPts
-
seg
-
allowSnappingToSourceVertices
private boolean allowSnappingToSourceVertices -
isClosed
private boolean isClosed
-
-
Constructor Details
-
LineStringSnapper
Creates a new snapper using the points in the givenLineString
as source snap points.- Parameters:
srcLine
- a LineString to snap (may be empty)snapTolerance
- the snap tolerance to use
-
LineStringSnapper
Creates a new snapper using the given points as source points to be snapped.- Parameters:
srcPts
- the points to snapsnapTolerance
- the snap tolerance to use
-
-
Method Details
-
setAllowSnappingToSourceVertices
public void setAllowSnappingToSourceVertices(boolean allowSnappingToSourceVertices) -
isClosed
-
snapTo
Snaps the vertices and segments of the source LineString to the given set of snap vertices.- Parameters:
snapPts
- the vertices to snap to- Returns:
- a list of the snapped points
-
snapVertices
Snap source vertices to vertices in the target.- Parameters:
srcCoords
- the points to snapsnapPts
- the points to snap to
-
findSnapForVertex
-
snapSegments
Snap segments of the source to nearby snap vertices. Source segments are "cracked" at a snap vertex. A single input segment may be snapped several times to different snap vertices.For each distinct snap vertex, at most one source segment is snapped to. This prevents "cracking" multiple segments at the same point, which would likely cause topology collapse when being used on polygonal linework.
- Parameters:
srcCoords
- the coordinates of the source linestring to be snappedsnapPts
- the target snap vertices
-
findSegmentIndexToSnap
Finds a src segment which snaps to (is close to) the given snap point.Only a single segment is selected for snapping. This prevents multiple segments snapping to the same snap vertex, which would almost certainly cause invalid geometry to be created. (The heuristic approach to snapping used here is really only appropriate when snap pts snap to a unique spot on the src geometry.)
Also, if the snap vertex occurs as a vertex in the src coordinate list, no snapping is performed.
- Parameters:
snapPt
- the point to snap tosrcCoords
- the source segment coordinates- Returns:
- the index of the snapped segment or -1 if no segment snaps to the snap point
-