Hi,
I am trying to create a polygon to outline a set of roads based on a sample of coordinates. I can do this in Matlab with the function called `polybuffer’. I have been struggling to find an equivalent function in the Shapley package. Here is a simple example to illustrate the differences I have encountered:
As you can see, the code from Matlab looks more like roads whereas the Python code creates a convex polygon.
The only other requirement I have is that I need to be able to add a buffer and test whether a given point is within the buffer (e.g., the filled area in the matlabplot). I looked into alpha shapes, but I did not find a way to test the intersection of a point.
Is there a Python solution?
Thanks in advance for your help.
Corresponding code:
Python
from shapely.geometry import Point, LineString, Polygon
from shapely.ops import unary_union
from matplotlib import pyplot as plt
buffer = .05
poly1 = Polygon([(0,0), (2,0), (2,2), (0,2)]).buffer(buffer)
poly2 = Polygon([(2,2), (4,2), (4,4), (2,4)]).buffer(buffer)
poly3 = Polygon([(1,1), (3,1), (3,3), (1,3)]).buffer(buffer)
poly4 = Polygon([(3,3), (5,3), (5,5), (3,5)]).buffer(buffer)
polys = [poly1, poly2, poly3, poly4]
polygon_union = unary_union(polys)
fig, axs = plt.subplots()
axs.set_aspect('equal', 'datalim')
xs, ys = polygon_union.exterior.xy
axs.plot(xs, ys, alpha=0.5)
plt.plot(xs, ys)
Matlab
buffer = .05
coords = [0 0; 2 0; 2 2; 0 2]
polygon(1) = polybuffer(coords, 'lines', buffer)
coords = [2 2; 4 2; 4 4; 2 4]
polygon(2) = polybuffer(coords, 'lines', buffer)
coords = [1 1; 3 1; 3 3; 1 3]
polygon(3) = polybuffer(coords, 'lines', buffer)
coords = [3 3; 5 3; 5 5; 3 5]
polygon(4) = polybuffer(coords, 'lines', buffer)
union_polygon = union(polygon)
plot(union_polygon)