PostGISGeometry Editors

ST_Segmentize

What is ST_Segmentize?

ST_Segmentize densifies a geometry by adding vertices so that no segment is longer than the specified threshold. It is available for both geometry and geography types.

SQL
1ST_Segmentize(geometry geom, float max_segment_length)geometry
2ST_Segmentize(geography geog, float max_segment_length_meters) → geography

On geometry, segments are interpolated linearly. On geography, the interpolation follows great-circle paths and distance is measured in metres.

When would you use ST_Segmentize?

Use ST_Segmentize before reprojecting long line segments across CRSs where the transformation is non-linear — a single transatlantic segment reprojected without densification can appear badly distorted. Densify first, then ST_Transform, to preserve curvature.

It is also useful before computing buffers, distances, or clipping against grids with varying resolution, where evenly-spaced vertices produce more predictable results.

FAQs

What units does the length argument use?

CRS units for geometry (metres for EPSG:3857, degrees for EPSG:4326). For geography, always metres along the great circle.

Does ST_Segmentize change the visual shape?

On geometry it preserves shape exactly — only extra collinear vertices are added. On geography the added vertices follow a great-circle arc, so reprojections appear more accurately curved.

Why densify before ST_Transform?

CRS transformations are nonlinear. Long segments cross large angular ranges and can deviate substantially from the true geodesic after simple endpoint reprojection. Segmentising first reduces per-segment angular span and preserves curvature.

How is it related to ST_LineSubstring?

ST_LineSubstring extracts a portion of a line by fractional position. ST_Segmentize adds vertices uniformly along the whole line without extracting anything.