st_isring.sql 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. -- The ring_linestring table is created with two columns:
  2. -- a smallint column, gid, uniquely identifies the rows,
  3. -- while ln1, a ST_LineString column, stores the ST_LineString geometries.
  4. CREATE TABLE ring_linestring (gid smallint,
  5. ln1 ST_LineString);
  6. -- The INSERT statements insert three linestrings into the ln1 column.
  7. -- The first row contains a linestring that's not closed and isn't a ring.
  8. -- The second row contains a closed and simple linestring that is a ring.
  9. -- The third row contains a linestring that is closed but not simple because
  10. -- it intersects its own interior. It's also not a ring.
  11. INSERT INTO ring_linestring VALUES(
  12. 1,
  13. ST_LineFromText('linestring (10.02 20.01,10.32 23.98,11.92 25.64)', 1000)
  14. );
  15. INSERT INTO ring_linestring VALUES(
  16. 2,
  17. ST_LineFromText('linestring (10.02 20.01,11.92 35.64,25.02 34.15,19.15 33.94, 10.02 20.01)', 1000)
  18. );
  19. INSERT INTO ring_linestring VALUES(
  20. 3,
  21. ST_LineFromText('linestring (15.47 30.12,20.73 22.12,10.83 14.13,16.45 17.24,21.56 13.37,11.23 22.56,19.11 26.78,15.47 30.12)', 1000)
  22. );
  23. -- The query returns the results of the ST_IsRing function.
  24. -- The first and third rows return false because the linestrings aren't
  25. -- rings, while the second row returns t (TRUE) because it is a ring.
  26. SELECT gid, ST_IsRing(ln1) Is_it_a_ring
  27. FROM ring_linestring;