-
Notifications
You must be signed in to change notification settings - Fork 219
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
Figure.plot: parameter aspatial does not accept integers for filling polygons #2497
Comments
For GeoPandas objects, PyGMT calls the tempfile_from_json function to save the GeoPandas object into a ".gmt" file (using the
and pass the file If you open the file
For unknown reasons, |
In other words, we need to understand why |
Here is a simplified version to reproduce the issue:
The first few lines of the
As you can see, |
One more update here.
The variable
The Looks like a fiona issue? |
Opened an issue in the fiona repo @seisman. Will wait for an answer and hopefully fix before continuing with the corresponding gallery example. |
Update on the integer issue. This behavior is expected. The OGR_GMT driver only supports 32 bit integers, floats, and datetimes. All other types are converted to strings: https://github.com/OSGeo/gdal/blob/6e9103bd5acb1ff8da305c4e77fa30335ffa3b70/ogr/ogrsf_frmts/gmt/ogrgmtlayer.cpp#L769. This means we have to decide how we want to handle other types as input @GenericMappingTools/pygmt-maintainers. |
We don't have many options:
For option 3, I thought |
This issue is almost the same as geopandas/geopandas#967 and the workaround here geopandas/geopandas#967 (comment) works. See #2592 for the patch. |
Need to patch upstream
import pandas as pd
import pygmt
import geopandas as gpd
world = gpd.read_file(gpd.datasets.get_path("naturalearth_lowres"))
europe = world.query(expr="continent == 'Europe'")
europe.loc[:, "pop_est_int"] = round(europe.pop_est * 1e-6).astype(pd.Int32Dtype())
fig = pygmt.Figure()
pygmt.makecpt(cmap="lajolla", series=[0, 150, 50], continuous=True)
fig.basemap(region=[-12, 35, 35, 60], projection="M12c", frame=True)
fig.plot(
data=europe,
pen="1p,black",
close=True,
fill="+z",
cmap=True,
aspatial="Z=pop_est_int",
)
fig.colorbar(position="JMR", frame="a10+lPopulation in millions")
fig.show() However, I did |
Description of the problem
When using polygons (e.g. read in via geopandas), the
aspatial
parameter of Figure.plot does not accept integers for filling the corresponding polygons (the polygons remain empty). First they need to be converted to float.Minimal Complete Verifiable Example
Full error message
No response
System information
The text was updated successfully, but these errors were encountered: