ST_Perimeter
What is ST_Perimeter?
ST_Perimeter returns the 2D perimeter — the boundary length — of a polygonal geometry. For POLYGON it is the length of the outer ring plus the lengths of any holes; for MULTIPOLYGON it is the sum across all parts.
1ST_Perimeter(geometry g1) → float
2ST_Perimeter(geography geog, boolean use_spheroid = true) → floatFor non-polygonal input (points, lines, collections without polygons), the function returns 0. For geography, the result is in metres on the WGS84 spheroid by default.
When would you use ST_Perimeter?
Use ST_Perimeter to compute the boundary length of an area feature: fencing requirements around a property, shoreline length around an island, or sewer-line requirements along a subdivision boundary. It is also the denominator in compactness metrics such as (4π·area)/perimeter², useful for comparing polygon regularity.
1-- Perimeter in metres of each country boundary on lat/lon data
2SELECT iso_code, ST_Perimeter(geom::geography) AS metres
3FROM countries;FAQs
What units does ST_Perimeter return?
For geometry, the units of the SRID — degrees for EPSG:4326, metres for projected CRSs. For geography, always metres on the WGS84 spheroid. Cast lat/lon geometry to geography when you need real-world metres.
Does it include holes?
Yes. A polygon with interior rings contributes its outer ring length plus all hole lengths. This matches OGC semantics: if you fenced the polygon, you would fence the inner boundaries too.
What does it return for non-polygonal input?
Zero. For linestring length use ST_Length; for collections extract polygons first with ST_CollectionExtract(geom, 3).
Is there a 3D version?
Yes — ST_3DPerimeter uses Z coordinates to return the slope perimeter, useful for polygons draped over terrain.