keplergl / kepler.gl

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
http://kepler.gl
MIT License
10.38k stars 1.74k forks source link

[Bug][Jupyter Widget] add_data with GeoDataFrame only works if the geometry column is called "geometry" #1758

Open remi-sap opened 2 years ago

remi-sap commented 2 years ago

Describe the bug add_data using a GeoDataFrame fails if the geometry column is not called "geometry". The geometry is often called "geometry" but this is not a given.

To Reproduce Steps to reproduce the behavior:

import pandas as pd
import geopandas
import keplergl
from shapely.geometry import Point
df = pd.DataFrame(
    {'City': ['Buenos Aires', 'Brasilia'],
     'Country': ['Argentina', 'Brazil'],
     'PT': [Point(-34.58,-58.66), Point(-15.78, -47.91)]
})
point_gdf = geopandas.GeoDataFrame(df, geometry='PT')
w1 = keplergl.KeplerGl(height=500)
w1.add_data(data=point_gdf, name='cities')

Error Message: AttributeError: 'DataFrame' object has no attribute 'geometry' with a stack pointing to the file keplergl.py line 44: df[name] = df.geometry.apply(lambda x: shapely.wkt.dumps(x))

Expected behavior No error message

Environment (please complete the following information):

Additional context Can be fixed with 1 key stroke :-) replace df[name] = df.geometry.apply(lambda x: shapely.wkt.dumps(x)) by df[name] = gdf.geometry.apply(lambda x: shapely.wkt.dumps(x))

I'll submit a pull request :-)

remi-sap commented 2 years ago

Pull request for the fix by changing dfto gdf is here