-
Notifications
You must be signed in to change notification settings - Fork 369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: inconsistency between prepared and unprepared polygon contains predicate #740
Comments
In fact the test_line is NOT contained by the test_poly, since an endpoint of the line falls outside the polygon. This is likely due to the issue described in locationtech/jts#396. Because the current Relate algorithm nodes the input before computing the DE-9IM topology, it can happen that due to robustness the noding causes the line endpoint and the computed node to be (incorrectly) identical. (This is not surprising, since the line endpoint is the computed intersection of a longer line with the polygon.) Prepared Contains doesn't node the input, but uses (more) robust topological predicates. So it computes the correct answer. Fixing this is going to require a new Relate algorithm, unfortunately. |
Thanks for investigating! In my case I was relying on (unprepared) contains giving me the right answer, so that I could attribute the line I clipped by the polygon as being (effectively) within the polygon. Good to know that in the future this could change and I may have to calculate the degree of intersection to get to the same result (i.e., >99% within is good enough). |
In the (currently experimental) |
Here's a minimal reproducer:
Contains = |
Great to see
Here's the command to evaluate the minimal repro above:
|
I'm seeing cases where the contains predicate is true when the polygon is not prepared, but false when the polygon is prepared. The polygon is valid, so I don't think that is the issue. In this case, the line is created by clipping a larger line to the polygon. Example WKT files attached.
In contrast, the line is always within the polygon, regardless of whether or not the line is prepared.
I didn't see a way to use prepared predicates with
geosop
, but here is what I am doing with Shapely 2.0b2 / GEOS 3.11:This might be a special case where the endpoint of the line is within the boundary of the polygon (fails ContainsProperly), which perhaps is causing one of the speedups in the prepared Contains predicate to fail when it shouldn't.
test_poly.wkt.zip
test_line.wkt.zip
The text was updated successfully, but these errors were encountered: