dtoolkit.geoaccessor.geoseries.geobuffer#

dtoolkit.geoaccessor.geoseries.geobuffer(s: GeoSeries, distance: int | float | list[int | float] | ndarray | Series, /, **kwargs) GeoSeries[source]#

Creates geographic buffers for GeoSeries.

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 s. For GeoDataFrame.geobuffer, it would use the column name as the distance prior.

Returns:
GeoSeries
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 of s.

  • If distance is a Series but its index does not match the index of s.

Warns:
UserWarning
  • If the index of the inputting is not unique.

  • If the CRS of the inputting is not WGS84 (epsg:4326).

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]