dtoolkit.geoaccessor.dataframe.from_wkt#

dtoolkit.geoaccessor.dataframe.from_wkt(df: pd.DataFrame, /, geometry: Hashable, crs: CRS | str | int = None) gpd.GeoDataFrame[source]#

Generate GeoDataFrame of geometries from ‘WKT’ column of DataFrame.

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

Parameters:
geometryHashable

The name of WKT 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

Notes

This method is the accessor of DataFrame, not GeoDataFrame.

Examples

>>> import dtoolkit.geoaccessor
>>> import pandas as pd
>>> df = pd.DataFrame(
...     {
...         "wkt": [
...             "POINT (1 1)",
...             "POINT (2 2)",
...             "POINT (3 3)",
...         ]
...     }
... )
>>> df
           wkt
0  POINT (1 1)
1  POINT (2 2)
2  POINT (3 3)
>>> df.from_wkt("wkt", crs=4326)
           wkt                 geometry
0  POINT (1 1)  POINT (1.00000 1.00000)
1  POINT (2 2)  POINT (2.00000 2.00000)
2  POINT (3 3)  POINT (3.00000 3.00000)