st_boundary.sql 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. -- In this example the boundary_test table is created with two columns:
  2. -- geotype defined as a varchar, and g1 defined as the superclass geometry.
  3. -- The INSERT statements that follow insert each one of the subclass
  4. -- geometries. The ST_Boundary function retrieves the boundary of each
  5. -- subclass stored in the g1 geometry column. Note that the dimension of
  6. -- the resulting geometry is always one less than the input geometry.
  7. -- Points and multipoints always result in a boundary that is an empty
  8. -- geometry, dimension -1. Linestrings and multilinestrings return
  9. -- a multipoint boundary, dimension 0. A polygon or multipolygon always
  10. -- returns a multilinestring boundary, dimension 1.
  11. CREATE TABLE boundary_test (geotype varchar(20),
  12. g1 ST_Geometry);
  13. INSERT INTO boundary_test VALUES(
  14. 'Point', ST_PointFromText('point (10.02 20.01)',1000)
  15. );
  16. INSERT INTO boundary_test VALUES(
  17. 'Linestring',
  18. ST_LineFromText('linestring (10.02 20.01,10.32 23.98,11.92 25.64)',1000)
  19. );
  20. INSERT INTO boundary_test VALUES(
  21. 'Polygon',
  22. ST_PolyFromText('polygon ((10.02 20.01,11.92 35.64,25.02 34.15,19.15 33.94, 10.02 20.01))',1000)
  23. );
  24. INSERT INTO boundary_test VALUES(
  25. 'Multipoint',
  26. ST_MPointFromText('multipoint (10.02 20.01,10.32 23.98,11.92 25.64)',1000)
  27. );
  28. INSERT INTO boundary_test VALUES(
  29. 'Multilinestring',
  30. ST_MLineFromText('multilinestring ((10.02 20.01,10.32 23.98,11.92 25.64), (9.55 23.75,15.36 30.11))',1000)
  31. );
  32. INSERT INTO boundary_test VALUES(
  33. 'Multipolygon',
  34. ST_MPolyFromText('multipolygon (((10.02 20.01,11.92 35.64,25.02 34.15,19.15 33.94,10.02 20.01)),((51.71 21.73,73.36 27.04,71.52 32.87,52.43 31.90,51.71 21.73)))',1000)
  35. );
  36. SELECT geotype, ST_Boundary(g1)
  37. FROM boundary_test;