dtoolkit.geoaccessor.dataframe.from_wkb#
- dtoolkit.geoaccessor.dataframe.from_wkb(df: pd.DataFrame, /, geometry: Hashable, crs: CRS | str | int = None) gpd.GeoDataFrame [source]#
Generate
GeoDataFrame
of geometries from ‘WKB’ column ofDataFrame
.A sugary syntax wraps
geopandas.GeoSeries.from_wkb()
.- Parameters:
- geometryHashable
The name of WKB column.
- 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
See also
Notes
This method is the accessor of DataFrame, not GeoDataFrame.
Read from file (such as “CSV” or “EXCEL”), requreis converting “WKB” columns type from
str
tobytes
viaeval
.
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.to_frame().from_wkb("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'>