From e938eaa6141e8d5762eb67b79c5485d5b9b782b0 Mon Sep 17 00:00:00 2001 From: Charbel Abi Daher <45701489+CharbelAD@users.noreply.github.com> Date: Thu, 26 Aug 2021 15:12:56 +0300 Subject: [PATCH] Added buffer distance in get_streets() Added a buffer distance in get_streets() to fetch streets that are not fully inside the perimeter. --- prettymaps/fetch.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/prettymaps/fetch.py b/prettymaps/fetch.py index c88fd7b..fd092f5 100644 --- a/prettymaps/fetch.py +++ b/prettymaps/fetch.py @@ -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) \ No newline at end of file + return get_geometries(**kwargs)