Introduction
Functions returning geometries
Collections
13. ST_Area
Summary

Instruction

Fine! You know that ST_Area returns the area of the polygon, but what happens if we use it with a collection? The answer is: it will return the total area of all polygons in the collection. For instance:

Well done! Now, you know that the ST_Area function returns the area of a polygon, but what happens if we pass in a collection to this function? Simply put, it calculates the total area of all polygons in the collection! This simplifies matters quite a bit, eliminating the need to call an aggregate function like SUM if you already have a collection on hand. For instance:

SELECT 
  id, 
  ST_Area(ST_Transform(geo_data,26910)) 
FROM sf_chains;

For each collection, the query above will show its id and the total area of all polygons it contains.

Exercise

What is the total area of all Tranquil Jewel Hotels in San Francisco (collection with id = 1)? Provide the answer in square meters.

Stuck? Here's a hint!

Remember to use ST_Tranform with an SRID of 26910 before you calculate ST_Area.

Console

Code editor

Result

TableConsole