Added buffer distance in get_streets()

Added a buffer distance in get_streets() to fetch streets that are not fully inside the perimeter.
This commit is contained in:
Charbel Abi Daher
2021-08-26 15:12:56 +03:00
committed by GitHub
parent 7f3aa74857
commit e938eaa614

View File

@@ -80,7 +80,7 @@ def get_geometries(perimeter = None, point = None, radius = None, tags = {}, per
return geometries
# Get streets
def get_streets(perimeter = None, point = None, radius = None, layer = 'streets', width = 6, custom_filter = None, circle = True, dilate = 0):
def get_streets(perimeter = None, point = None, radius = None, layer = 'streets', width = 6, custom_filter = None, buffer = 0,circle = True, dilate = 0):
if layer == 'streets':
layer = 'highway'
@@ -88,13 +88,13 @@ def get_streets(perimeter = None, point = None, radius = None, layer = 'streets'
# Boundary defined by polygon (perimeter)
if perimeter is not None:
# Fetch streets data, project & convert to GDF
streets = ox.graph_from_polygon(unary_union(perimeter.geometry), custom_filter = custom_filter)
streets = ox.graph_from_polygon(unary_union(perimeter.geometry).buffer(buffer) if buffer > 0 else unary_union(perimeter.geometry), custom_filter = custom_filter)
streets = ox.project_graph(streets)
streets = ox.graph_to_gdfs(streets, nodes = False)
# Boundary defined by polygon (perimeter)
elif (point is not None) and (radius is not None):
# Fetch streets data, save CRS & project
streets = ox.graph_from_point(point, dist = radius+dilate, custom_filter = custom_filter)
streets = ox.graph_from_point(point, dist = radius+dilate+buffer, custom_filter = custom_filter)
crs = ox.graph_to_gdfs(streets, nodes = False).crs
streets = ox.project_graph(streets)
# Compute perimeter from point & CRS
@@ -146,4 +146,4 @@ def get_layer(layer, **kwargs):
return get_streets(**kwargs, layer = layer)
# Fetch geometries
else:
return get_geometries(**kwargs)
return get_geometries(**kwargs)