-
Notifications
You must be signed in to change notification settings - Fork 184
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
Simplifying polygons in build_shapes.py leads to holes and overlaps #1051
Comments
Hello @jome1! Fantastic, thanks a lot for sharing your in-depth research and a clear and elaborated explanation!! That is tremendously helpful. Dealing with with #382 has been quite a mystery for quite some time, while it seems that you have managed to resolve it 🎉 🎉 🎉 As for a solution, I fear that dropping @davide-f once you would have time, it would be great to have your opinion on possible solutions. |
Thanks for the praise! Yes, I also fear that dropping I am trying to use PyPSA-Earth to generate some data for Egypt. I have custom model regions (we merged some governorates together to have fewer regions). Therefore I once tried to use the original GADM level 1 files, merge them to my needs and insert them to PyPSA. The run was very long and ended in an error. This error is another thing one need to be aware of when using custom model regions. It means that I was only able to use the GADM files created by PyPSA and adapt them, instead of the original GADM files, because somehow the datastructure of the .geojson is different (even though all attribute columns are the same). So, the simplification function for the polygons is important. The good thing is that I just found out that in the blog post I posted above, which explains the whole polygon simplification of adjacent polygons really well, it is also mentioned that the developed simplification algorithm should also be downstreamed to I just hope that this process will not take too long. Maybe I'll find out their timeline. I also found an alternative solution, which could be used in the meantime. But maybe it is too much effort. |
I asked in the shapely repo and the needed function Unfortunately there is not yet a release date. But this sounds promising! |
Fantastic news! Thanks a lot for that 😄 |
Many thanks @jome1 !!! They are not available in the config file though, we calibrated as a trade-off between accuracy and computational time. |
Unfortunately, I have no idea when the 2.1 release will happen. |
main
branch or the latest release. Please indicate.pypsa-earth
environment. Update viaconda env update -f envs/environment.yaml
.Describe the Bug
The script
build_shapes.py
downloads the GADM layers from https://geodata.ucdavis.edu/gadm/gadm4.1/gpkg/{GADM_filename}.gpkg.When inspecting the created
gadm_shapes.geojson
closely, one can identify holes and overlaps between the polygons describing GADM layer 1 (here called "governorates"). See the following picture:I think this is because within the script
build_shapes.py
the downloaded polygons are simplified.The following picture compares the original boarders of the governorates with the simplified boardes. Thereby the newly created and simplified polygons at some locations either overlap or leave holes in between.
In other words: The polygons are all simplified seperately. So shared boarders (edges) are not considered.
This problem might also play a role when using GADM layers as the fundamental shapes as for example mentioned by @pz-max in #382 and when building the bus regions.
Possible solution
Polygons can only be simplified where they are not sharing the line with another polygon (so skip the simplification for shared boarders) OR the conterminous (neighbouring) polygons have to be simplified to the same line.
I did a little internet search.
Maybe shapely.snap could help to solve this problem.
helpful mini threads about this phenomenon:
Unfortunately, ArcGis is not free, but this is exactly what we need: https://pro.arcgis.com/en/pro-app/latest/tool-reference/cartography/simplify-shared-edges.htm
this looks also very promising: https://lin-ear-th-inking.blogspot.com/2023/03/simplifying-polygonal-coverages-with-jts.html
The text was updated successfully, but these errors were encountered: