Functions / PostGIS / ST_Snap
PostGISGeometry Editors

ST_Snap

What is ST_Snap?

ST_Snap moves vertices and segments of the input geometry to align with the vertices of a reference geometry, when within the supplied tolerance. It is designed to reconcile slightly offset features so that overlay operations produce clean topology.

SQL
ST_Snap(geometry input, geometry reference, float tolerance)geometry

The tolerance is in CRS units. The reference geometry is not modified.

When would you use ST_Snap?

Use ST_Snap to align neighbouring parcel polygons whose shared boundaries differ by a few centimetres due to independent digitising — a common issue when merging cadastral data from multiple sources. Snapping before ST_Union prevents sliver polygons along almost-matching edges.

It is also useful in road-network integration: snapping a new road segment's endpoints to an existing junction vertex ensures topological connectivity for routing tools.

FAQs

Does the reference geometry change?

No. Only the input geometry is adjusted. To snap both in opposite directions, call ST_Snap twice with the arguments swapped.

How large should the tolerance be?

Small — a few times the expected digitising error. Too large a tolerance can merge genuinely separate features, damaging topology.

What's the difference from ST_SnapToGrid?

ST_SnapToGrid rounds to a regular grid independent of any reference feature. ST_Snap aligns to specific vertices of another geometry — a targeted topology-aware snap.

Is ST_Snap transitive?

No. Snapping A to B then B to A does not always produce the same result as snapping in one step. Plan the order of operations when chaining multiple snaps.