Class GeometrySnapper
java.lang.Object
org.locationtech.jts.operation.overlay.snap.GeometrySnapper
Snaps the vertices and segments of a
Geometry
to another Geometry's vertices.
A snap distance tolerance is used to control where snapping is performed.
Snapping one geometry to another can improve
robustness for overlay operations by eliminating
nearly-coincident edges
(which cause problems during noding and intersection calculation).
It can also be used to eliminate artifacts such as narrow slivers, spikes and gores.
Too much snapping can result in invalid topology being created, so the number and location of snapped vertices is decided using heuristics to determine when it is safe to snap. This can result in some potential snaps being omitted, however.
- Version:
- 1.7
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionGeometrySnapper
(Geometry srcGeom) Creates a new snapper acting on the given geometry -
Method Summary
Modifier and TypeMethodDescriptionprivate double
static double
Estimates the snap tolerance for a Geometry, taking into account its precision model.static double
static double
private double
computeSnapTolerance
(Coordinate[] ringPts) Computes the snap tolerance based on the input geometries.private Coordinate[]
static Geometry[]
Snaps two geometries together with a given tolerance.Snaps the vertices in the componentLineString
s of the source geometry to the vertices of the given snap geometry.snapToSelf
(double snapTolerance, boolean cleanResult) Snaps the vertices in the componentLineString
s of the source geometry to the vertices of the same geometry.static Geometry
snapToSelf
(Geometry geom, double snapTolerance, boolean cleanResult) Snaps a geometry to itself.
-
Field Details
-
SNAP_PRECISION_FACTOR
private static final double SNAP_PRECISION_FACTOR- See Also:
-
srcGeom
-
-
Constructor Details
-
GeometrySnapper
Creates a new snapper acting on the given geometry- Parameters:
srcGeom
- the geometry to snap
-
-
Method Details
-
computeOverlaySnapTolerance
Estimates the snap tolerance for a Geometry, taking into account its precision model.- Parameters:
g
- a Geometry- Returns:
- the estimated snap tolerance
-
computeSizeBasedSnapTolerance
-
computeOverlaySnapTolerance
-
snap
Snaps two geometries together with a given tolerance.- Parameters:
g0
- a geometry to snapg1
- a geometry to snapsnapTolerance
- the tolerance to use- Returns:
- the snapped geometries
-
snapToSelf
Snaps a geometry to itself. Allows optionally cleaning the result to ensure it is topologically valid (which fixes issues such as topology collapses in polygonal inputs).Snapping a geometry to itself can remove artifacts such as very narrow slivers, gores and spikes.
- Parameters:
geom
- the geometry to snapsnapTolerance
- the snapping tolerancecleanResult
- whether the result should be made valid- Returns:
- a new snapped Geometry
-
snapTo
Snaps the vertices in the componentLineString
s of the source geometry to the vertices of the given snap geometry.- Parameters:
snapGeom
- a geometry to snap the source to- Returns:
- a new snapped Geometry
-
snapToSelf
Snaps the vertices in the componentLineString
s of the source geometry to the vertices of the same geometry. Allows optionally cleaning the result to ensure it is topologically valid (which fixes issues such as topology collapses in polygonal inputs).- Parameters:
snapTolerance
- the snapping tolerancecleanResult
- whether the result should be made valid- Returns:
- a new snapped Geometry
-
extractTargetCoordinates
-
computeSnapTolerance
Computes the snap tolerance based on the input geometries.- Parameters:
ringPts
-- Returns:
-
computeMinimumSegmentLength
-