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
orient function should work on folded polygons #1705
Comments
Assuming that your import shapely
poly0 = shapely.Polygon(poly0)
poly1 = shapely.Polygon(poly1) then the problem here is that those are not "valid" Polygons: >>> poly0.is_valid
False
>>> poly1.is_valid
False
>>> shapely.is_valid_reason(poly0)
'Ring Self-intersection[-70 20]'
>>> shapely.is_valid_reason(poly1)
'Ring Self-intersection[-70 20]' And many of the shapely functions are not guaranteed to work fully correctly with non-valid geometries. If you want to represent such a polygon, you actually need a MultiPolygon: >>> shapely.make_valid(poly0).wkt
'MULTIPOLYGON (((-60 10, -70 10, -70 20, -60 20, -60 10)), ((-80 30, -70 30, -70 20, -81 20, -80 30)))' |
Try to embed this code in your example, it gives the same output with poly0 and poly1.
I don't know |
Thanks for your answer. I have tried this already in my real case. And it is not working.
A lot of non valid polygons, I don't know how to correct them. in fact only 1, 2 and 11 cause trouble when filled. |
Hi @PBrockmann I'm not sure what's the correct output, but as @jorisvandenbossche pointed out - some of your polygons are not valid and you could try to make them valid before calling You might want to try to take some ideas from this code:
|
Back to a simpler test that does not work (filling incorrect) event with shapely.geometry.polygon.orient
|
Oh, right, I've added support for this in #1690 |
Please apply #1690 and try this:
|
Hi, Tested again. Really confused in what to do. Your proposed code does not give a correct plot.
No the nearest good solution is:
But polygons near borders are not filled correctly: |
Hi @PBrockmann, I can suggest that for pinpointing the problem it might be helpful if you provided a minimal example that reproduces the issue (maybe like your first example, if that makes sense). |
Yes, many thanks for being helpful in trying to resolve this issue. I have tried to simplify the problem. But I am confused in the use of different parameters such as closed=True for Path structure in Matplotlib. The big picture is to be able to draw continents and all islands with a filled color. Some polygons (extracted from a VTK process) have holes. The matplotlib Patches are the right structure to handle this I think. But I have to respect orientation and that seems non trial when you have islands connected only by a vertex. Making them valid from a shapely point of view leads to other problems (why so many different types of geometry once valid ?). So yes confusing for a request quite simple in fact. |
Hi, I have a small case extracted from my real polygons that explains the problem and that I cannot solve.
Inpecting the coordinates show the problem:
The polygon coordinates is folded. When it is fully describes anti-clockwise then the filling is correct. So how to do this ? Correct all polygons. |
If many of your polygons are not valid maybe it explains all the filling problems, so maybe run |
Hi, I come back on this issue. Because folded polygons cannot be drawn on a map.
The first polygon is not drawn, the second is drawn. The first one is folded and detected as oriented counter clock-wise. That is partially true. How can I repair this orientation ? |
Any news on this problem ?
polygon1 is not drawn. So how to correct polygon1 ? |
Here is a solution I have found. The strategy is to separate the folded polygon into multiple polygons, orient them correclty with shapely then build a patch matplotlib object. Here is the code to correct polygon1 that is a folded polygon.
|
And to close this issue. So same strategy. Separate the different self intersected polygons from their duplicate points into multiple polygons.
|
I have encountered a problem with folded polygons that despite the use of ``shapely.geometry.polygon.orient``` are not describe fully oriented counter-clockwise.
I have described the problem from the cartopy project but this issue is in fact related to shapely.
See: SciTools/cartopy#2111
Initialy from: https://stackoverflow.com/questions/74710358/how-to-detect-inner-polygons-from-a-multipolygon-shapely-object
So my question is:
How to force the orientation of a folded polygon to be oriented counter-clockwise ?
The text was updated successfully, but these errors were encountered: