st_exteriorring.sql 1.3 KB

12345678910111213141516171819202122232425262728
  1. -- An ornithologist, wishing to study the bird population on several south
  2. -- sea islands, knows that the feeding zone of the bird species she is
  3. -- interested in is restricted to the shoreline. As part of her calculation
  4. -- of the island's carrying capacity the ornithologist requires the islands'
  5. -- perimeters. Some of the islands are so large they have several ponds on
  6. -- them. However, the shoreline of the ponds are inhabited exclusively by
  7. -- another more aggressive bird species. Therefore, the ornithologist
  8. -- requires the perimeter of the exterior ring only of the islands.
  9. -- The ID and name columns of the islands table identifies each island,
  10. -- while the land polygon column stores the island's geometry.
  11. CREATE TABLE islands (id integer,
  12. name varchar(32),
  13. land ST_Polygon);
  14. INSERT INTO islands VALUES(
  15. 1,
  16. 'hawaii',
  17. ST_PolyFromText('polygon ((42000 18000,48000 18000,48000 13000,42000 13000,42000 18000))',1000)
  18. );
  19. -- The ST_ExteriorRing function extracts the exterior ring from each
  20. -- island polygon as a linestring. The length of the linestring is
  21. -- calculated by the ST_Length function. The linestring lengths are
  22. -- summarized by the sum function.
  23. SELECT SUM(ST_Length(ST_ExteriorRing(land)))
  24. FROM islands;