1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
"""Accessors for accessing GeoPandas functionality via pandas extension dtypes."""
import pandas.api.extensions
from geopandas import GeoSeries
from geopandas.array import GeometryDtype
@pandas.api.extensions.register_series_accessor("geo")
class GeoSeriesAccessor:
"""Series.geo accessor to expose GeoSeries methods on pandas Series.
Parameters
----------
series : pandas.Series
A Series with geometry dtype.
"""
def __init__(self, series):
if not isinstance(series.dtype, GeometryDtype):
raise AttributeError("Can only use .geo accessor with GeometryDtype values")
self._geoseries = GeoSeries(series)
def __getattr__(self, name):
return getattr(self._geoseries, name)
|