I'm new to Open Street Map and PostGIS, and am trying to figure out how to find all of the ways that intersect a linestring (i.e. all of the streets that intersect a route). Is there a way to do this that doesn't involve calling ST_Intersects on every row of the table?

1 Answer 1


What you are looking for is only checking for intersecting within a bounding box. See: Selecting by bounding box with PostGIS

  • 1
    Just to be clear: you're not saying that ST_Intersects and intersection with the BB are the same thing; you're simply suggesting making a preliminary selection based on intersection with the BB and following that up with the ST_Intersects tests, right?
    – whuber
    Jan 1, 2012 at 14:46
  • Yes, sorry it was newyear night and i drank a lot of champagne. I could have been a little bit more elaborate.
    – mrg
    Jan 1, 2012 at 15:26
  • ST_Intersects makes a bbox (if possible index-based) first selection before doing the "real" computation. Jan 2, 2012 at 20:59
  • Thanks, I ended up getting all of the lines that intersect the linestring's bounding box and then used ST_DWithin to find the intersections.
    – Marc Regan
    Jan 12, 2012 at 17:34
  • I find it a bit weird to use ST_DWithin for your needs. Do you check on distance = 0?
    – mrg
    Jan 12, 2012 at 19:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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