[
https://issues.apache.org/jira/browse/SEDONA-456?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17800759#comment-17800759
]
Kristin Cowalcijk commented on SEDONA-456:
------------------------------------------
The reason is thatÂ
[SedonaMapUtils._{_}convert_to_gdf{_}_|https://github.com/apache/sedona/blob/sedona-1.5.0/python/sedona/maps/SedonaMapUtils.py#L36-L37]
renames the geometry column to "geometry" using the {{rename}} method. This
method won't change the geometry column of GeoDataFrame accordingly. The
correct way of doing this is by calling the
[{{rename_geometry}}|https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoDataFrame.rename_geometry.html]
method.
> SedonaKepler cannot work with geopandas >= 0.13.0 correctly
> -----------------------------------------------------------
>
> Key: SEDONA-456
> URL: https://issues.apache.org/jira/browse/SEDONA-456
> Project: Apache Sedona
> Issue Type: Bug
> Affects Versions: 1.5.0
> Reporter: Kristin Cowalcijk
> Priority: Major
>
> The following exception is raised when adding a dataframe with a geometry
> column not named "geometry" to the map. If the geometry column is renamed to
> "geometry" before adding to the map, then everything goes well.
> {code}
> ---------------------------------------------------------------------------
> AttributeError Traceback (most recent call last)
> File
> ~/Library/Python/3.9/lib/python/site-packages/geopandas/geodataframe.py:436,
> in GeoDataFrame.crs(self)
> 435 try:
> --> 436 return self.geometry.crs
> 437 except AttributeError:
> File
> ~/Library/Python/3.9/lib/python/site-packages/pandas/core/generic.py:5487, in
> NDFrame.__getattr__(self, name)
> 5486 return self[name]
> -> 5487 return object.__getattribute__(self, name)
> File
> ~/Library/Python/3.9/lib/python/site-packages/geopandas/geodataframe.py:235,
> in GeoDataFrame._get_geometry(self)
> 229 msg += (
> 230 "\nThere are no existing columns with geometry data type.
> You can "
> 231 "add a geometry column as the active geometry column with
> "
> 232 "df.set_geometry. "
> 233 )
> --> 235 raise AttributeError(msg)
> 236 return self[self._geometry_column_name]
> AttributeError: You are calling a geospatial method on the GeoDataFrame, but
> the active geometry column ('seg') is not present.
> There are columns with geometry data type (['geometry']), and you can either
> set one as the active geometry with df.set_geometry("name") or access the
> column as a GeoSeries (df["name"]) and call the method directly on it.
> During handling of the above exception, another exception occurred:
> AttributeError Traceback (most recent call last)
> Cell In[16], line 3
> 1 mapAll = SedonaKepler.create_map()
> ----> 3 SedonaKepler.add_df(mapAll, df, name="Segs")
> 5 mapAll
> File
> ~/Library/Python/3.9/lib/python/site-packages/sedona/maps/SedonaKepler.py:52,
> in SedonaKepler.add_df(cls, kepler_map, df, name)
> 44 """
> 45 Adds a SedonaDataFrame to a given map object.
> 46 :param kepler_map: Map object to add SedonaDataFrame to
> (...)
> 49 :return: Does not return anything, adds df directly to the given map
> object
> 50 """
> 51 geo_df = SedonaMapUtils.__convert_to_gdf__(df)
> ---> 52 kepler_map.add_data(geo_df, name=name)
> File ~/Library/Python/3.9/lib/python/site-packages/keplergl/keplergl.py:140,
> in KeplerGl.add_data(self, data, name)
> 129 def add_data(self, data, name="unnamed"):
> 130 ''' Send data to Voyager
> 131
> 132 Inputs:
> (...)
> 137 keplergl.add_data(data_string, name="data_1")
> 138 '''
> --> 140 normalized = _normalize_data(data)
> 141 copy = self.data.copy()
> 142 copy.update({name: normalized})
> File ~/Library/Python/3.9/lib/python/site-packages/keplergl/keplergl.py:50,
> in _normalize_data(data)
> 48 def _normalize_data(data):
> 49 if isinstance(data, pd.DataFrame):
> ---> 50 return _gdf_to_dict(data) if isinstance(data,
> geopandas.GeoDataFrame) else _df_to_dict(data)
> 51 return data
> File ~/Library/Python/3.9/lib/python/site-packages/keplergl/keplergl.py:34,
> in _gdf_to_dict(gdf)
> 25 ''' Create an input dict for kepler.gl using a GeoDataFrame object
> 26
> 27 Inputs:
> (...)
> 31 - dictionary: a dictionary variable that can be used in Kepler.gl
> 32 '''
> 33 # reproject to 4326 if needed
> ---> 34 if gdf.crs and not gdf.crs == 4326:
> 35 gdf = gdf.to_crs(4326)
> 37 # get name of the geometry column
> 38 # will cause error if data frame has no geometry column
> File
> ~/Library/Python/3.9/lib/python/site-packages/pandas/core/generic.py:5487, in
> NDFrame.__getattr__(self, name)
> 5480 if (
> 5481 name not in self._internal_names_set
> 5482 and name not in self._metadata
> 5483 and name not in self._accessors
> 5484 and self._info_axis._can_hold_identifiers_and_holds_name(name)
> 5485 ):
> 5486 return self[name]
> -> 5487 return object.__getattribute__(self, name)
> File
> ~/Library/Python/3.9/lib/python/site-packages/geopandas/geodataframe.py:438,
> in GeoDataFrame.crs(self)
> 436 return self.geometry.crs
> 437 except AttributeError:
> --> 438 raise AttributeError(
> 439 "The CRS attribute of a GeoDataFrame without an active "
> 440 "geometry column is not defined. Use
> GeoDataFrame.set_geometry "
> 441 "to set the active geometry column."
> 442 )
> AttributeError: The CRS attribute of a GeoDataFrame without an active
> geometry column is not defined. Use GeoDataFrame.set_geometry to set the
> active geometry column.
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)