Share via


st_perimeter function

Applies to: check marked yes Databricks Runtime 17.1 and above

Important

This feature is in Public Preview.

Returns the perimeter of the input GEOGRAPHY or GEOMETRY value.

Syntax

st_perimeter ( geoExpr )

Arguments

  • geoExpr: A GEOGRAPHY or GEOMETRY value.

Returns

A value of type DOUBLE, representing the perimeter of the input GEOGRAPHY or GEOMETRY value.

If the input is a GEOGRAPHY value, the function the geodesic perimeter of the input GEOGRAPHY value. Specifically, it returns the sum of the geodesic lengths of the (2D projections of the) segments of a polygon, and the sum of the perimeters of the polygons in a multipolygon. For non-areal geographies (points, linestrings, multipoints, and multilinestrings) 0 is returned, whereas for geometry collections it returns the sum of the perimeters of the elements in the collection. The result is computed by performing the inverse geodesic calculation assuming the WGS84 ellipsoid. The units of the result is meters.

If the input is a GEOMETRY value, the function returns the Cartesian perimeter of the input GEOMETRY value. Specifically, it returns the sum of the lengths of the (2D Cartesian projections of the) segments of a polygon, and the sum of the perimeters of the polygons in a multipolygon. For non-areal geometries (points, linestrings, multipoints, and multilinestrings) 0 is returned, whereas for geometry collections it returns the sum of the perimeters of the elements in the collection. The units of the result are those of the spatial reference system of the input GEOMETRY value.

The function returns NULL if any of the inputs is NULL.

Examples

-- Returns the perimeter of a 2D Cartesian polygon with a hole.
> SELECT round(st_perimeter(st_geomfromtext('POLYGON((0 0,50 0,50 50,0 50,0 0),(20 20,25 30,30 20,20 20))')), 2)
  232.36