3

I have a street network from many of links in a PostgreSQL table. Some links have no connection to the network. I want to isolate these links from the network. Each link has a geometry (geom) and id column.

How can I get the linkids from the network, which don't touch any other links? Maybe the function is st_touches, but how can I ask this on the whole network from each link?

enter image description here

6

On a properly noded network, you could use also use st_intersects

So, one could select all records where no other records (with a different ID) intersects. It would be querying the same layer twice:

SELECT l1.id
FROM links l1
WHERE NOT EXISTS
 (SELECT 1 
  FROM links l2
  WHERE l1.id != l2.id
  AND ST_INTERSECTS(l1.geom, l2.geom)
 )
2
  • I have a mistake of thought: the lines can be compound from more than one links. For my problem i need two steps. Step 1 should be to union all links touching the links tehreafter or bevor. After that in Step 2 isolate the links that have no connections to the network. How can i union the contiguous links to one line ?
    – Tibor
    Aug 19 at 15:33
  • You can use ST_LineMerge with ST_Collect to merge contiguous lines (keeping nodes of degree > 2). The downside is that this loses attribution on the lines.
    – dr_jts
    Aug 21 at 3:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.