ST_Length2D
What is ST_Length2D?
ST_Length2D returns the 2D length of a linear geometry. It is effectively a name alias of ST_Length for geometry input and exists primarily for API symmetry with ST_3DLength.
ST_Length2D(geometry a_2dlinestring) → floatThe result ignores any Z values in the input and is expressed in the CRS units of the geometry.
When would you use ST_Length2D?
Use ST_Length2D when you want to be explicit that your length computation is the planimetric (map-view) length, as opposed to the slope length. This is often the right choice for cartographic measurements on 3D data — for example, the on-map length of a pipeline regardless of elevation changes. It pairs naturally with ST_3DLength to compute a slope-over-plan ratio.
1-- Slope ratio of a contoured cable run
2SELECT id,
3 ST_3DLength(geom) / NULLIF(ST_Length2D(geom), 0) AS slope_factor
4FROM cables;FAQs
How is ST_Length2D different from ST_Length?
For geometry input they are equivalent. ST_Length2D exists to make the 2D intent explicit, especially alongside ST_3DLength. Only ST_Length accepts geography.
What units does it return?
The CRS units of the input — degrees for EPSG:4326, metres for most projected CRSs. There is no geography overload.
Does it consider Z coordinates?
No. ST_Length2D explicitly ignores Z. Use ST_3DLength if you need the true slope length including elevation.
What does it return for non-linear input?
Zero. Polygons, points, and collections without linear components return 0. For polygon boundary length use ST_Perimeter2D.