-
Notifications
You must be signed in to change notification settings - Fork 228
Unable to handle GeoDataFrame with mixed Polygons/Multipolygons #2405
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
Labels
wontfix
This will not be worked on
Comments
Is it still a bug? The following script works well for me: import geopandas as gpd
import pygmt
world = gpd.read_file(gpd.datasets.get_path("naturalearth_lowres"))
world["pop_est"] = world.pop_est * 1e-6
cmap_bounds = pygmt.info(data=world["pop_est"], per_column=True)
fig = pygmt.Figure()
fig.basemap(region="d", projection="H15c", frame=True)
pygmt.makecpt(series=cmap_bounds, cmap="bilbao")
fig.plot(
data=world,
pen="1p,black",
close=True,
fill="+z",
cmap=True,
aspatial="Z=pop_est",
)
fig.colorbar(frame=True, cmap=True)
fig.show()
|
Ping @weiji14 |
Hmm, the world map does seem to get plotted properly now: My version information:
Not sure if it's something that has changed with |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Description of the problem
Originally reported at https://forum.generic-mapping-tools.org/t/not-able-to-draw-closed-polygons-using-pygmt/3663. After some investigation, tt seems that the
plot
function is unable to plotgeopandas.GeoDataFrame
objects that contain both Polygon and MultiPolygon shapes. Plotting just Polygon or just MultiPolygon works.Minimal Complete Verifiable Example
Run on Binder: https://mybinder.org/v2/gh/GenericMappingTools/egu22pygmt/main?urlpath=lab/tree/book/ecosystem.ipynb
This is the first 5 rows of the table
When trying to plot the full GeoDataFrame with mixed Polygon/MultiPolygons, it fails
produces

But plotting just MultiPolygon works.
produces

I've also documented a workaround using https://geopandas.org/en/v0.12.2/docs/reference/api/geopandas.GeoDataFrame.explode.html to convert all MultiPolygons to Polygons at https://forum.generic-mapping-tools.org/t/not-able-to-draw-closed-polygons-using-pygmt/3663/3, but it's not exactly ideal for some use cases.
Full error message
System information
Related
Ideally, there should be a way to read in standard OGR files like GeoJSON directly GenericMappingTools/gmt#4599. Having a mix of Polygons/MultiPolygons is fairly common.
The text was updated successfully, but these errors were encountered: