dtoolkit.geoaccessor.series.from_wkb#

dtoolkit.geoaccessor.series.from_wkb(s: pd.Series, /, crs: CRS | str | int = None) gpd.GeoDataFrame[source]#

Generate GeoDataFrame of geometries from Series.

A sugary syntax wraps geopandas.GeoSeries.from_wkb().

Parameters:
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.

Returns:
GeoDataFrame
Raises:
ValueError

If the name of Series is empty.

Notes

  • This method is the accessor of Series, not GeoSeries.

  • Read from file (such as “CSV” or “EXCEL”), requreis converting “WKB” column type from str to bytes via eval.

Examples

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