st_pointonsurface.sql 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. -- The city engineer wishes to create a label point for each building's
  2. -- footprint. The building footprints are stored in the buildingfootprints
  3. -- table that was created with the following CREATE TABLE statement.
  4. CREATE TABLE buildingfootprints (building_id integer,
  5. lot_id integer,
  6. footprint ST_MultiPolygon);
  7. INSERT INTO buildingfootprints VALUES(
  8. 506, 1010,
  9. 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)
  10. );
  11. INSERT INTO buildingfootprints VALUES(
  12. 543, 2930,
  13. 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)
  14. );
  15. INSERT INTO buildingfootprints VALUES(
  16. 1208, 203,
  17. 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)
  18. );
  19. INSERT INTO buildingfootprints VALUES(
  20. 178, 5192,
  21. 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)
  22. );
  23. -- The ST_PointOnSurface function generates a point that is guaranteed
  24. -- to be on the surface of the building footprints.
  25. SELECT building_id, ST_PointOnSurface(footprint)
  26. FROM buildingfootprints;