dtoolkit.geoaccessor.geodataframe.geobuffer#
- dtoolkit.geoaccessor.geodataframe.geobuffer(df: GeoDataFrame, distance: Hashable | int | float | list[int | float] | ndarray | Series, /, **kwargs) GeoDataFrame [source]#
Creates geographic buffers for
GeoDataFrame
.Reprojects input features into the UTM projection, buffers them, then reprojects back into the original geographic coordinates.
- Parameters:
- distanceint, float, list-like of int or float, the unit is meter.
The radius of the buffer. If numpy.ndarray or Series are used then it must have same length as the
df
. ForGeoDataFrame.geobuffer
, it would use the column name as the distance prior.
- Returns:
- GeoDataFrame
- Raises:
- ValueError
Requires the CRS of the inputting is WGS84 (epsg:4326).
- TypeError
If
distance
is not a number.- IndexError
If
distance
is a list-like but its length does not match the length ofdf
.If
distance
is a Series but its index does not match the index ofdf
.
- Warns:
- UserWarning
If the index of the inputting is not unique.
If the CRS of the inputting is not WGS84 (epsg:4326).
See also
Examples
>>> import dtoolkit.geoaccessor >>> import pandas as pd >>> df = ( ... pd.DataFrame( ... { ... "distance": [0, 10], ... "where": ["close to equator", "away from equator"], ... "x": [122, 100], ... "y": [55, 1], ... }, ... ) ... .from_xy( ... "x", ... "y", ... crs=4326, ... ) ... .drop(columns=["x", "y"]) ... ) >>> df distance where geometry 0 0 close to equator POINT (122.00000 55.00000) 1 10 away from equator POINT (100.00000 1.00000) >>> df.geobuffer(100) distance ... geometry 0 0 ... POLYGON ((122.00156 55.00001, 122.00156 54.999... 1 10 ... POLYGON ((100.00090 1.00000, 100.00089 0.99991... [2 rows x 3 columns]
For GeoDataFrame, it could use the column name as the distance to generate buffer.
>>> df.geobuffer("distance") distance ... geometry 0 0 ... POLYGON EMPTY 1 10 ... POLYGON ((100.00009 1.00000, 100.00009 0.99999... [2 rows x 3 columns]