Returns the 2D perimeter of a geometry or geography object.
Syntax
float ST_Perimeter(geometry g1);
float ST_Perimeter(geography geog, boolean useSpheroid);Parameters
| Parameter | Description |
|---|---|
g1 | A geometry object. |
geog | A geography object. |
useSpheroid | Specifies whether to use an ellipsoid. |
Description
For ST_Surface and ST_MultiSurface objects (polygons and MultiPolygons), ST_Perimeter returns the 2D perimeter.
For non-areal objects (points, lines), ST_Perimeter returns
0. To get the length of a linear geometry, use ST_Length instead.For geometry objects, the result is in the unit defined by the object's spatial reference system (SRS).
For geography objects, the result is an inverse geodesic distance measured in meters.
Examples
Calculate the perimeter of a polygon. The result is in the unit defined by the object's SRS.
SELECT ST_Perimeter('POLYGON((0 0,0 2,2 2,2 0,0 0))'::geometry);Result:
st_perimeter
--------------
8
(1 row)The polygon has vertices at (0,0), (0,2), (2,2), and (2,0), forming a 2x2 square with perimeter 8.