st_touches.sql 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. -- The GIS technician has been asked by his boss to provide a list
  2. -- of all sewer lines whose endpoints intersect another sewer line.
  3. -- The sewerlines table is created with three columns.
  4. -- The first column, sewer_id, uniquely identifies each sewer line.
  5. -- The integer class column identifies the type of sewer line,
  6. -- generally associated with the line's capacity. The sewer
  7. -- ST_Linestring column stores the sewer line's geometry.
  8. CREATE TABLE sewerlines (sewer_id integer,
  9. class integer,
  10. sewer ST_LineString);
  11. INSERT INTO sewerlines VALUES(
  12. 1, 1,
  13. ST_LineFromText('linestring (42000 10000,46000 14000)',1000)
  14. );
  15. INSERT INTO sewerlines VALUES(
  16. 2, 2,
  17. ST_LineFromText('linestring (43000 11000,44000 10000)',1000)
  18. );
  19. INSERT INTO sewerlines VALUES(
  20. 3, 2,
  21. ST_LineFromText('linestring (42000 12000,43000 11000)',1000)
  22. );
  23. INSERT INTO sewerlines VALUES(
  24. 4, 2,
  25. ST_LineFromText('linestring (44000 12000,45000 11000)',1000)
  26. );
  27. INSERT INTO sewerlines VALUES(
  28. 5, 2,
  29. ST_LineFromText('linestring (43000 13000,44000 12000)',1000)
  30. );
  31. INSERT INTO sewerlines VALUES(
  32. 6, 2,
  33. ST_LineFromText('linestring (45000 13000,46000 12000)',1000)
  34. );
  35. INSERT INTO sewerlines VALUES(
  36. 7, 2,
  37. ST_LineFromText('linestring (44000 14000,45000 13000)',1000)
  38. );
  39. -- The query returns an ordered list of sewer_ids that touch one another.
  40. SELECT s1.sewer_id, s2.sewer_id
  41. FROM sewerlines s1, sewerlines s2
  42. WHERE ST_Touches(s1.sewer, s2.sewer);