1

Is there a way in Shapely to calculate intersections of geometries with some tolerance?

Imagine we have lines that are the same, but their coordinates are written with different precision.

LINESTRING(83 55, 84 56)
LINESTRING(83 55, 84.499999998 56.4999999998)

Or imagine a line had decimal fractions, and was rounded in another program, and returned back. I saw that rounding caused unexpected geometry behaviour (like lines that should intersect, do not because of 10th digit precision), so am trying to work around this.

The problem I'm solving is to find if a route in OSRM has passed through a certain segment in OSM highways, that are imported in Python separately from OSRM.

2
  • You could first buffer your lines by your desired tolerance and then check for intersection of the buffered lines.
    – davemfish
    Commented Apr 7, 2018 at 19:08
  • @davemfish: that's what I thought of. Buffer the route, then check the length of intersection with each segment or line.
    – culebrón
    Commented Apr 7, 2018 at 21:05

1 Answer 1

1

You cannot do that using intersection. If almost invisible changes in the geometries are not important, you can apply a very small buffer (with some tolerance you mentioned) before intersection.

For example:

l1 -> LINESTRING(83 55, 84 56)
l2 -> LINESTRING(83 55, 84.00001 56.00001)

l2.buffer(0.00001).intersection(l1) # returns l1

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.