liveBook · Manning

ST_Area

As explained in Just Use Postgres!

ST_Area is a PostGIS function that returns the area of a polygonal geometry in the units associated with its spatial reference system.

ST_Area calculates the area of a polygonal geometry. The result uses the units defined by the geometry’s spatial reference system (SRID), so a geometry stored with SRID 3857 produces square-meter values. section 10.3.3 section 10.5.2

Measure a theme park

Calculate Walt Disney World’s area in square kilometers and acres: SELECT name, tourism, ST_Area(way) / 1000000.0 AS area_sq_km, ST_Area(way) / 4046.86 AS area_acres FROM florida.planet_osm_polygon WHERE name = 'Walt Disney World'; The query returns approximately 96.08 square kilometers and 23,741.93 acres. section 10.5.2

Use ST_Area to:

  • Compare polygon sizes by ordering geometries with ORDER BY ST_Area(way). section 10.3.3
  • Convert raw SRID-based results into more practical units by dividing the returned value. section 10.5.2
Listing 10.17 Calculating the area of Walt Disney World
SELECT name, tourism,
  ST_Area(way) / 1000000.0 AS area_sq_km,
  ST_Area(way) / 4046.86 AS area_acres
FROM florida.planet_osm_polygon
WHERE name = 'Walt Disney World';

Runnable SQL for calculating a polygon’s area in square kilometers and acres. section 10.5.2

How Just Use Postgres! covers it

How deep it goes
Explains the function, SRID-defined units, ordering, and unit conversion, but does not develop geometric area theory.
Examples
Uses OpenStreetMap polygon tables, smallest named regions, and Walt Disney World area in square kilometers and acres.
What it assumes
Assumes familiarity with SQL tables and geometry columns while identifying polygons, MultiPolygons, and SRID-based units.
What you can do after
Apply it via PostGIS to calculate, sort, and convert polygon areas in SQL.
How it connects
Connects polygon and MultiPolygon geometries with SRID, spatial reference systems, ST_Within, and ST_Equals.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Just Use Postgres!. The section links point to the parts of the book it draws on.