Class EndpointSnapper

java.lang.Object
com.github.micycle1.geoblitz.EndpointSnapper

public class EndpointSnapper extends Object
Endpoint-only snapper with optional polygon-vertex anchoring.

Closes small endpoint gaps in near-coverage linework so edges meet at nodes, without moving polygon vertices or interior line vertices. Operates on endpoints only (not a general vertex/edge snapper).

Behavior

  • Clusters LineString endpoints within a tolerance (transitively) and snaps them to a representative.
  • If snap-to-valid is enabled, polygon vertices are included as immutable anchors: any cluster containing a polygon vertex snaps exactly to that vertex; polygon geometries themselves are never modified.
  • If snap-to-valid is disabled, polygons are ignored for snapping; clusters composed only of endpoints snap mutually to their mean coordinate.
  • Closed LineStrings (rings) are treated as polygons and are not moved.

Output

Returns a geometry mirroring the input structure: LineStrings are replaced by snapped copies; Polygons/MultiPolygons and other geometry types are returned unchanged.

Notes

  • Intended for near-coverage datasets that should form a valid coverage but don’t quite join exactly (tiny endpoint gaps, near-misses).
  • Tolerance is in the data’s units; proximity is evaluated in XY only (Z/M are preserved by copy).
  • Typically followed by noding and polygonization if faces need to be built.
Author:
Michael Carleton
  • Constructor Details

    • EndpointSnapper

      public EndpointSnapper(double tolerance)
  • Method Details

    • snapEndpoints

      public org.locationtech.jts.geom.Geometry snapEndpoints(org.locationtech.jts.geom.Geometry geom, boolean snapToValid)
      Snap only the endpoints of LineStrings. If snapToValid is true, polygon vertices act as anchors: any cluster containing a polygon vertex snaps to that vertex; polygon geometries themselves are never modified. Returns a Geometry preserving the input's structure, with snapped LineStrings.