dtoolkit.geoaccessor.dataframe.from_xy#
- dtoolkit.geoaccessor.dataframe.from_xy(df: pd.DataFrame, /, x: Hashable, y: Hashable, z: Hashable = None, crs: CRS | str | int = None) gpd.GeoDataFrame[source]#
Generate
GeoDataFrameofPointgeometries from columns ofDataFrame.A sugary syntax wraps
geopandas.points_from_xy().- Parameters:
- xHashable
df’s column name.- yHashable
df’s column name.- zHashable, optional
df’s column name.- 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.
This method could be called via
df.points_from_xyordf.from_xy.
Examples
>>> import dtoolkit.geoaccessor >>> import pandas as pd >>> df = pd.DataFrame({"x": [122, 100], "y":[55, 1]}) >>> df x y 0 122 55 1 100 1 >>> df.from_xy("x", "y", crs="EPSG:4326") x y geometry 0 122 55 POINT (122 55) 1 100 1 POINT (100 1)