st_area.sql 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. -- The city engineer needs a list of building areas.
  2. -- To create the list, a GIS technician selects the
  3. -- building ID and area of each building's footprint.
  4. -- The building footprints are stored in the buildingfootprints
  5. -- table created with the following CREATE TABLE statement.
  6. CREATE TABLE buildingfootprints (building_id integer,
  7. lot_id integer,
  8. footprint ST_MultiPolygon);
  9. INSERT INTO buildingfootprints VALUES(
  10. 506, 1010,
  11. ST_MPolyFromText('multipolygon (((7.0 45.0,15.0 45.0,15.0 51.0,18.0 51.0,18.0 54.0,8.0 54.0,8.0 51.0,7.0 51.0,7.0 45.0)))',1000)
  12. );
  13. INSERT INTO buildingfootprints VALUES(
  14. 543, 2930,
  15. ST_MPolyFromText('multipolygon (((26.0 55.0,38.0 55.0,38.0 48.0,34.0 48.0,34.0 50.0,26.0 50.0,26.0 55.0)))',1000)
  16. );
  17. INSERT INTO buildingfootprints VALUES(
  18. 1208, 203,
  19. ST_MPolyFromText('multipolygon (((8.0 39.0,12.0 39.0,12.0 33.0,17.0 33.0,17.0 22.0,8.0 22.0,8.0 39.0)))',1000)
  20. );
  21. INSERT INTO buildingfootprints VALUES(
  22. 178, 5192,
  23. ST_MPolyFromText('multipolygon (((26.0 33.0,38.0 33.0,38.0 24.0,33.0 24.0,33.0 27.0,26.0 27.0,26.0 33.0)))',1000)
  24. );
  25. -- To satisfy the city engineer's request the technician selects
  26. -- the unique key, the building_id, and the area of each building
  27. -- footprint from the buildingfootprints table.
  28. SELECT building_id, ST_Area(footprint) area
  29. FROM buildingfootprints;