Buffer Around Geometries¶
GeoKit allows you to create buffers around specific geometries. This feature is useful for investigating exclusion zones or determining if different objects are within one another's influence zone.
In this example, we demonstrate how to apply a buffer around the German federal state of Brandenburg.
import pathlib
from geokit.core.get_test_data import get_test_data
import geokit.core.vector
import geokit.core.geom
gadm36_deu_1_path = get_test_data(
file_name="gadm36_DEU_1.shp",
)
federal_states_germany = geokit.core.vector.extractFeatures(gadm36_deu_1_path)
Highlight Brandenburg without Buffer¶
# highlight one geom
brandenburg_state_geom = federal_states_germany.geom.iloc[3]
ax_handle_basic_plot_1 = geokit.core.geom.drawGeoms(federal_states_germany, figsize=(6, 6))
ax_handle_brandenburg_unbuffered = geokit.core.geom.drawGeoms(
brandenburg_state_geom, ax=ax_handle_basic_plot_1, figsize=(6, 6), fc="red"
)
Highlight Brandenburg With Buffer¶
The buffer is created using the spatial reference system (SRS) of the vector.
Identify the spatial reference system of the vector file¶
To identify the spatial reference system (SRS) of the vector file, use the vectorInfo() function, as shown below. The shapefile examined uses the SRS EPSG 4326, which uses degrees of latitude and longitude as units of measurement. Thus we are going to define the buffer in the unit degree.
vector_info_shape_file = geokit.core.vector.vectorInfo(gadm36_deu_1_path)
print(vector_info_shape_file.srs)
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,
AUTHORITY["EPSG","9122"]],
AXIS["Latitude",NORTH],
AXIS["Longitude",EAST],
AUTHORITY["EPSG","4326"]]
Define the Buffer¶
We define a one-degree buffer around the Brandenburg federal state polygon. The results are plotted.
# use a buffer around the highlighted area with '.Buffer()'
brandenburg_state_geom_buffered = federal_states_germany.geom.iloc[3].Buffer(1)
ax_handle_basic_plot_1 = geokit.core.geom.drawGeoms(federal_states_germany, figsize=(6, 6))
ax_handle_buffered = geokit.core.geom.drawGeoms(
brandenburg_state_geom_buffered, ax=ax_handle_basic_plot_1, figsize=(6, 6), fc="red"
)