Reputation: 6333
I recently posted a question on how to plot a heatmap using geopandas. I was recommended to use geoplot.kdeplot()
, but passing a projection
crashes my session.
Suppose I have the following data stored in df_points
and df_map
respectively:
> print(df_points)
PointID geometry
0 204403876 POINT (-101.66700 21.11670)
1 204462769 POINT (-101.66700 21.11670)
2 144407530 POINT (-101.66700 21.11670)
> print(df_map)
PolyID geometry
0 01001 POLYGON ((-102.10641 22.06035, -102.10368 22.0...
1 01002 POLYGON ((-102.05189 22.29144, -102.05121 22.2...
2 01003 POLYGON ((-102.68569 22.09963, -102.69087 22.0...
This is what I tried, but according to this tutorial, I should pass a projection
to the heatmap.
# Import geoplot
import geoplot
import geoplot.crs as gcrs
# Plot points
ax = geoplot.kdeplot(df_points, shade=True, alpha=0.7)
# Plot polygons
geoplot.polyplot(df_map, ax=ax)
However, if I add projection=gcrs.AlbersEqualArea()
, my session crashes:
# Plot heatmap
ax = geoplot.kdeplot(df_points, cmap='Reds', shade=True,
projection=gcrs.AlbersEqualArea()) # This crashes my session ):
# Add polygons
geoplot.polyplot(df_map, ax=ax)
python3: geos_ts_c.cpp:3991: int GEOSCoordSeq_getSize_r(GEOSContextHandle_t, const geos::geom::CoordinateSequence*, unsigned int*): Assertion `0 != cs' failed.
How can I pass projection=gcrs.AlbersEqualArea()
and avoid the error?
Upvotes: 1
Views: 2654
Reputation: 35205
I'm commenting on a previous question: I've just run the example in the official geoplot reference with Colab and experienced a similar crash. After some research I found that the crash was caused by shaply and uninstalled and reinstalled it and the graphs were displayed as per the reference. Please give it a try.
pip uninstall shapely
pip install shapely --no-binary shapely
Here are the answers that helped me
Upvotes: 3