st_numgeometries.sql 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. -- The city engineer needs to know the number of distinct buildings
  2. -- associated with each building footprint.
  3. -- The building footprints are stored in the buildingfootprints table
  4. -- that was created with the following CREATE TABLE statement.
  5. CREATE TABLE buildingfootprints (building_id integer,
  6. lot_id integer,
  7. footprint ST_MultiPolygon);
  8. INSERT INTO buildingfootprints VALUES(
  9. 506, 1010,
  10. 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)
  11. );
  12. INSERT INTO buildingfootprints VALUES(
  13. 543, 2930,
  14. 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)
  15. );
  16. INSERT INTO buildingfootprints VALUES(
  17. 1208, 203,
  18. 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)
  19. );
  20. INSERT INTO buildingfootprints VALUES(
  21. 178, 5192,
  22. 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)
  23. );
  24. -- The query lists the building_id that uniquely identifies each building
  25. -- and the number of buildings in each footprint with the ST_NumGeometries
  26. -- function.
  27. SELECT building_id, ST_NumGeometries(footprint) no_of_buildings
  28. FROM buildingfootprints;