Model / geo · All operations

Measure area and length

A variant of Work with geography

Compute the area, length or perimeter of each geometry.

Status

In arcform

Runs as a SQL step

arcform carries it as a sql: step today, with the spatial extension.

The DuckDB step

Measure the area, length and perimeter of each geometry

SQL
INSTALL spatial; LOAD spatial; SET geometry_always_xy = true;

CREATE TEMP TABLE shapes AS SELECT * FROM (VALUES
  ('rectangle', ST_GeomFromText('POLYGON ((0 0, 4 0, 4 3, 0 3, 0 0))')),
  ('with hole', ST_GeomFromText('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (2 2, 4 2, 4 4, 2 4, 2 2))')),
  ('road', ST_GeomFromText('LINESTRING (0 0, 3 4, 3 10)')),
  ('degree box', ST_GeomFromText('POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))'))) t(name, geom);
-- planar measures in the units of the coordinates; area and perimeter are zero for a line and length is zero for a polygon
CREATE TEMP TABLE planar AS SELECT name, ST_Area(geom) AS area, ST_Length(geom) AS length, ST_Perimeter(geom) AS perimeter FROM shapes;
-- on the earth: the same box in degrees, measured on the WGS84 ellipsoid in metres
CREATE TEMP TABLE on_earth AS SELECT ST_Area_Spheroid(geom) AS area_m2, ST_Perimeter_Spheroid(geom) AS perimeter_m, ST_Length_Spheroid(ST_GeomFromText('LINESTRING (0 0, 1 0)')) AS equator_degree_m FROM shapes WHERE name = 'degree box';
SELECT * FROM planar ORDER BY name;
SELECT * FROM on_earth;
-- the spheroid values are those of geographiclib on the same box: area 12308778361.469452 m2, perimeter 443770.91724830196 m
SELECT CASE WHEN ((SELECT area = 12 AND perimeter = 14 FROM planar WHERE name = 'rectangle')
  AND (SELECT area = 96 AND perimeter = 48 FROM planar WHERE name = 'with hole')
  AND (SELECT length = 11 AND area = 0 FROM planar WHERE name = 'road')
  AND (SELECT abs(area_m2 - 12308778361.469452) < 1e-3 AND abs(perimeter_m - 443770.91724830196) < 1e-6 AND abs(equator_degree_m - 111319.49079327357) < 1e-6 FROM on_earth)) THEN 'as expected' ELSE error('the rectangle should measure 12 and 14, the polygon with a hole 96 and 48, the road 11 long, and the one-degree box 12308778361 m2 on the ellipsoid') END AS verdict;
  • The statement builds its own data.
  • It needs the spatial extension.
  • The statement checks its own result and raises an error when it is wrong: “the rectangle should measure 12 and 14, the polygon with a hole 96 and 48, the road 11 long, and the one-degree box 12308778361 m2 on the ellipsoid”.
  • It passed on DuckDB v2.0.0 (Cyanoptera) d54cbbe3df.

What other tools call it

Meridian's classification; an independent blind rating agreed on 95.7% of 324 rows (variant, version 3).

Alteryx Designer (1)
  • Spatial Inforead 2026-09-27

    Extract area, length, centroid, bounding box, point count and type from a spatial object

Duckle (3)
  • Spatial Arearead 2026-09-25

    area of each polygon, planar or spheroid by CRS

  • Spatial Lengthread 2026-09-25

    length of each line, planar or spheroid by CRS

  • Spatial Perimeterread 2026-09-25

    perimeter of each polygon, planar or spheroid by CRS

Ibis (3)

Background

In PostGIS, ST_Area returns the area of a polygonal geometry, and ST_Length returns the length of a linear one.[1][2] In PostGIS, ST_Perimeter returns the perimeter of a polygon or multipolygon, and 0 for geometries that are not areal.[3]

When to use it

In PostGIS, ST_Length returns 0 for areal geometries, and ST_Perimeter is the function to use for a polygon's boundary.[2] In DuckDB's spatial extension, ST_Area returns 0.0 for any geometry that is not a polygon, a multipolygon or a geometry collection containing polygons.[4]

When applied to world maps, the Mercator projection inflates the size of lands the farther they are from the equator.[5] An equal-area projection preserves relative area between all regions of a map, but by Gauss's Theorema Egregium it cannot be conformal, so it distorts shapes.[6] Measure areas on the ellipsoid or in an equal-area projection, never in Mercator coordinates. (Meridian's view) In PostGIS, measuring the area of a geography on the spherical model with ST_Area(geog, false) is faster but less accurate than the default spheroid.[1]

The fractal nature of a coastline makes precise measurement of its length difficult if not impossible.[7] Compare the lengths of natural features only between layers digitised at the same level of detail. (Meridian's view)

The method

The shoelace formula, also known as Gauss's area formula and the surveyor's formula, determines the area of a simple polygon from the Cartesian coordinates of its vertices.[8] The shoelace formula was described by Albrecht Ludwig Friedrich Meister in 1769 and is based on the trapezoid formula described by Carl Friedrich Gauss and C.G.J. Jacobi.[8]

Since PostGIS 2.2.0, area measurement on the spheroid has been performed with GeographicLib for improved accuracy and robustness.[1]

Sources

  1. [1]ST_Areadocumentation
  2. [2]ST_Lengthdocumentation
  3. [3]ST_Perimeterdocumentation
  4. [4]Spatial Functions – DuckDBdocumentation
  5. [5]Mercator projection - Wikipediasecondary source
  6. [6]Equal-area projection - Wikipediasecondary source
  7. [7]Spatial analysis - Wikipediasecondary source
  8. [8]Shoelace formula - Wikipediasecondary source