st_centroid.sql 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. -- The building footprints are stored in the buildingfootprints table
  2. -- that is created with the following CREATE TABLE statement.
  3. CREATE TABLE buildingfootprints (building_id integer,
  4. lot_id integer,
  5. footprint ST_Multipolygon);
  6. INSERT INTO buildingfootprints VALUES(
  7. 506, 1010,
  8. 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)
  9. );
  10. INSERT INTO buildingfootprints VALUES(
  11. 543, 2930,
  12. 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)
  13. );
  14. INSERT INTO buildingfootprints VALUES(
  15. 1208, 203,
  16. 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)
  17. );
  18. INSERT INTO buildingfootprints VALUES(
  19. 178, 5192,
  20. 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)
  21. );
  22. -- The centroid function returns the centroid of each building footprint
  23. -- multipolygon.
  24. SELECT building_id, ST_Centroid(footprint) Centroid
  25. FROM buildingfootprints;