H3-Pandas
H3-Pandas copied to clipboard
geopandas integration, support arbitrary geometry column name
Awesome project, makes life much easier.
It seems like this could use a tighter geopandas integration. I noticed that this assumes the geometry column is named "geometry" which is not always the case.
You can get the active geometry column name with gdf.geometry.name
where gdf.geometry
attribute is always the active geometry. This works in geopandas 0.14.2.
I peaked at the source code, it seems like sometimes the gdf.geometry attribute is used in the source, but maybe it just looks for a column named "geometry" because it assumes it's a pandas dataframe. I'm not sure
Reproduction steps
I noticed this when running code something like this:
gdf = gdf.set_geometry("points_geometry") # The only geometry column, contains several points
h3.geo_to_h3_aggregate(7, return_geometry=True)
I got this error:
TypeError: 'GeometryArray' with dtype geometry does not support reduction 'sum'
The above exception was the direct cause of the following exception:
TypeError: agg function failed [how->sum,dtype->geometry]
If I rename and drop the original geometry, it works
gdf["geometry"] = gdf.points_geometry
gdf = gdf.set_geometry("geometry").drop(columns="points_geometry")
h3agg = gdf.h3.geo_to_h3_aggregate(7, return_geometry=True)