12

I am trying to create square buffers around given points, I am able to create circular buffers but how do I create square ones?

from shapely.ops import transform
from shapely.geometry import Point
    local_azimuthal_projection = "+proj=aeqd +R=6371000 +units=m +lat_0={} +lon_0={}".format(lat, lon)
                    wgs84_to_aeqd = partial(
                        pyproj.transform,
                        pyproj.Proj('+proj=longlat +datum=WGS84 +no_defs'),
                        pyproj.Proj(local_azimuthal_projection),
                    )
                    aeqd_to_wgs84 = partial(
                        pyproj.transform,
                        pyproj.Proj(local_azimuthal_projection),
                        pyproj.Proj('+proj=longlat +datum=WGS84 +no_defs'),
                    )

                    point_transformed = transform(wgs84_to_aeqd, Point(float(lon), float(lat)))
                    buffer = point_transformed.buffer(0.5*1000)
                    buffered_geom = transform(aeqd_to_wgs84, buffer).exterior.coords[:]
0

1 Answer 1

22

Here is how you can create square buffers using geopandas. Note that geometric operations in geopandas are performed by shapely.

import geopandas as gpd
from shapely.geometry import Point
import matplotlib.pyplot as plt

# Generate some sample data 
p1 = Point((1,2))
p2 = Point((6,8))
points = gpd.GeoSeries([p1,p2])

# Buffer the points using a square cap style
# Note cap_style: round = 1, flat = 2, square = 3
buffer = points.buffer(2, cap_style = 3)

# Plot the results
fig, ax1 = plt.subplots()
buffer.boundary.plot(ax=ax1, color = 'slategrey')
points.plot(ax = ax1, color = 'red')

enter image description here

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.