dtoolkit.geoaccessor.series.to_geoframe#

dtoolkit.geoaccessor.series.to_geoframe(s: pd.Series, /, geometry: gpd.GeoSeries = None, crs: CRS | str | int = None, **kwargs) gpd.GeoDataFrame | pd.DataFrame[source]#

Transform an array of shapely scalars Series to a GeoDataFrame.

Parameters:
geometryGeoSeries, optional

It will be prior set as ‘geometry’ column on GeoDataFrame. If the input is a GeoSeries, its index will be ignored.

crsCRS, str, int, optional

Coordinate Reference System of the geometry objects. Can be anything accepted by from_user_input(), such as an authority string (eg “EPSG:4326” / 4326) or a WKT string.

**kwargs

See the documentation for GeoDataFrame and for complete details on the keyword arguments.

Returns:
DataFrame or GeoDataFrame

GeoDataFrame if the data is an array of shapely scalars or geometry is set.

Examples

>>> import dtoolkit.geoaccessor
>>> import pandas as pd
>>> s = pd.Series(
...     pd.Series(
...         [
...             "POINT (1 1)",
...             "POINT (2 2)",
...             "POINT (3 3)",
...         ],
...         name="wkt",
...     )
...     .from_wkt(crs=4326)
...     .geometry
... )
>>> s
0    POINT (1.00000 1.00000)
1    POINT (2.00000 2.00000)
2    POINT (3.00000 3.00000)
Name: geometry, dtype: geometry
>>> type(s)
<class 'pandas.core.series.Series'>
>>> gs = s.to_geoframe()
>>> gs
                    geometry
0    POINT (1.00000 1.00000)
1    POINT (2.00000 2.00000)
2    POINT (3.00000 3.00000)
>>> type(gs)
<class 'geopandas.geodataframe.GeoDataFrame'>