-
Notifications
You must be signed in to change notification settings - Fork 562
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
[cascaded_union] TopologyException: self intersection error #829
Comments
|
@Jingnan1783 would you be willing to upgrade to shapely 1.7.0 and try unary_union instead of cascaded_union? Still, it's going to be difficult to reproduce this without data or a script that will generate artificial data. |
|
pose_table.txt |
|
@sgillies After more debugging, we've found that the polygons that caused the issue are actually a series of rectangles (same centroid, same dimension) rotating with very small angle around their centroid. I wonder if that rings a bell? Is that a known input that cascaded_union cannot support? |
|
@siyangy thanks for the details. I did some searching in the GEOS tracker and found
|
|
FWIW, this is a classic kind of dataset which causes overlay robustness errors (which is what is being reported by Cascaded Union). Specifically, overlaying geometries with nearly-coincident line segments. JTS is able to compute the Unary Union of this input. But GEOS has slightly different intersection code which might fail where JTS succeeds. Fixing the overlay algorithm in GEOS may have to wait for a newer version. The (very slight) good new is that this is a great test case for future development. A possible workaround is to use the buffer(0) trick (although this is quite .a bit slower). |
|
@dr-jts thank you! |
|
With the latest GEOS version (I tested GEOS 3.11.1, but I assume this will be the case for versions that include OverlayNG), I can confirm this now runs without exception. I didn't look in detail at the input geometries, so can't judge exactly if this looks OK but the unary_union gives: Closing as this should be solved by OverlayNG, which is already included in some GEOS versions / released shapely wheels. |

Please note
I was running the cascaded_union upon a list of polygons on my end. Then it throws an error message
TopologyException: Input geom 1 is invalid: Self-intersection at or near point -69.408611004575775 618.63706496565976 at -69.408611004575775 618.63706496565976.When debugging, I tried to union them one by one instead of calling the function all together, then this error message just disappeared.
Expected behavior and actual behavior.
My expected behavior for this function would be: given a list of polygons, the cascaded_union result of the list of polygons should equal to the cascaded_union of these polygons one by one. (like polygon 1 union with 2 and then 3 then 4....)
That means the order of how we union the polygons doesn't really matter. But it seems this is not true.
Steps to reproduce the problem.
I can't paste our data here but if you create a path then during the path you move forward and in some tick you move backwards for one step and then forward again, you can reproduce it I guess.
EDIT: added the data from file included below here as code example:
Operating system
Linux
Shapely version and provenance
Version: 1.5.13
The text was updated successfully, but these errors were encountered: