From fe0d3bcc28f723e97cfa4105bed83eb8bb85bbe5 Mon Sep 17 00:00:00 2001 From: Stefan Hansson Date: Mon, 16 Nov 2020 13:55:06 +0100 Subject: wip --- algorithms.py | 20 ++++++++++++++--- server.py | 21 +++++++++++++----- store.py | 62 +++++++++++++++++++++++++++++++++++++++++++++++++--- templates/index.html | 13 ++++++++++- templates/index.js | 5 ++++- 5 files changed, 108 insertions(+), 13 deletions(-) diff --git a/algorithms.py b/algorithms.py index 9f3fd78..9d4f538 100644 --- a/algorithms.py +++ b/algorithms.py @@ -1,5 +1,6 @@ import heapq import math +from store import get_relevant_neighbours def length_haversine(p1, p2): @@ -17,6 +18,7 @@ def length_haversine(p1, p2): return 6372797.560856 * c # return the distance in meters +<<<<<<< HEAD def grid_search(grid, source_node): """ Finds closest node to source node by comparing distance to nodes within @@ -72,19 +74,25 @@ def get_closest_node(nodes, source_node): Searches through all nodes in a specified grid and return node closes to source node. """ +def get_closest_node_id(nodes, source_node, transport_mode): + """ Search through all nodes and return the id of the node + that is closest to 'source_node'. """ min_node = None min_value = None for node in nodes: length = length_haversine(source_node, node) - if min_node is None or length < min_value: + + relevant_neighbours = get_relevant_neighbours(node, transport_mode) + + if (min_node is None or length < min_value) and relevant_neighbours: min_node = node min_value = length return min_node -def find_shortest_path(nodes, source_id, target_id): +def find_shortest_path(nodes, source_id, target_id, transport_mode: str): """ Return the shortest path using Dijkstra's algortihm. """ # queue contains multiple (walk_dist, (node_0, node_1, ... node_n))-tuples # where (node_0, node_1, ... node_n) is a walk to node_n @@ -102,10 +110,15 @@ def find_shortest_path(nodes, source_id, target_id): if walk_end in visited: # there exists a shorter walk to walk_end continue + # otherwise this is the shortest walk to walk_end visited.add(walk_end) # consider all our neighbours - for neighbour in nodes[walk_end].neighbours: + end_node = nodes[walk_end] + + relevant_neighbours = get_relevant_neighbours(end_node, transport_mode) + + for neighbour in relevant_neighbours: if neighbour in visited: # there exists a shorter walk to neighbour continue @@ -114,5 +127,6 @@ def find_shortest_path(nodes, source_id, target_id): new_dist = walk_dist + length_haversine(nodes[walk_end], neighbour) new_walk = walk + (neighbour.id,) heapq.heappush(queue, (new_dist, new_walk)) + # no path found return None diff --git a/server.py b/server.py index 25d2826..7c89bf6 100644 --- a/server.py +++ b/server.py @@ -47,17 +47,28 @@ def show_unconnected_nodes(): @post('/shortest-path') def shortest_path(body): body = json.loads(body) +<<<<<<< HEAD source_id = algorithms.grid_search(grid, store.Node(-1, body['lat1'], body['lng1'])) target_id = algorithms.grid_search(grid, store.Node(-1, body['lat2'], body['lng2'])) - - path = algorithms.find_shortest_path(nodes, source_id, target_id) - print(path) - response = { - "path": [(nodes[node].lat, nodes[node].lng) for node in path]} +======= + transport_mode = body['transport_mode'] + + source_id = algorithms.get_closest_node_id(nodes, + store.Node(-1, body['lat1'], + body['lng1']) + transport_mode) + target_id = algorithms.get_closest_node_id(nodes, + store.Node(-1, body['lat2'], + body['lng2']) + transport_mode) +>>>>>>> 532c0cb... wip + + path = algorithms.find_shortest_path(nodes, source_id, target_id, transport_mode) + response = {"path": [(nodes[node].lat, nodes[node].lng) for node in path]} return json.dumps(response) diff --git a/store.py b/store.py index c988e47..23dc50a 100644 --- a/store.py +++ b/store.py @@ -7,7 +7,8 @@ class Node: self.id = id self.lat = float(lat) self.lng = float(lng) - self.neighbours = [] + self.neighbours_bike = [] + self.neighbours_car = [] self.parent = None self.size = 1 @@ -45,25 +46,43 @@ class Node: parser = None # Have a global reusable parser object -def add_neighbours(nodes): +def add_neighbours_bike(nodes): for way in parser.iter_ways(): if 'highway' not in way['tags']: continue + print(way) + road = way['road'] for i in range(len(road) - 1): node1 = road[i] node2 = road[i + 1] +<<<<<<< HEAD nodes[node1].neighbours.append(nodes[node2]) nodes[node2].neighbours.append(nodes[node1]) # These two are neighbours and should be part of the same tree. nodes[node1].union(nodes[node2]) +======= + if suitable_car(way): + nodes[node1].neighbours_car.append(nodes[node2]) + nodes[node2].neighbours_car.append(nodes[node1]) + + if suitable_bike(way): + nodes[node1].neighbours_bike.append(nodes[node2]) + nodes[node2].neighbours_bike.append(nodes[node1]) +>>>>>>> 532c0cb... wip return nodes +def add_neighbours_car(nodes): + for way in parser.iter_ways(): + if 'highway' not in way['tags']: + continue + + def extract_osm_nodes(f_name): global parser parser = get_default_parser(f_name) @@ -78,7 +97,7 @@ def extract_osm_nodes(f_name): # Remove nodes without neighbours for node_id, node in nodes.copy().items(): - if not node.neighbours: + if not node.neighbours_car or not node.neighbours_bike: del nodes[node_id] # Construct a forest of disjoint trees. @@ -131,3 +150,40 @@ def select_nodes_in_rectangle(nodes, min_lat, max_lat, min_long, max_long): return [node for node in nodes.values() if min_lat <= node.lat <= max_lat and min_long <= node.lng <= max_long] + + +def get_relevant_neighbours(nodes, transport_mode): + if transport_mode == "bike": + return nodes.neighbours_bike + else: + return nodes.neighbours_car + + +suitable_highway_types_bike = [ + # Special road types + 'living_street', 'service', 'pedestrian', 'track', 'road' +] + +def suitable_bike(way): + tags = way['tags'] + + suitable_generic_type = tags['highway'] in suitable_highway_types_bike + suitable_bike = tags['bicycle'] == 'yes' if 'bicycle' in tags else False + + return suitable_generic_type or suitable_bike + + +suitable_highway_types_car = [ + # Roads + 'motorway', 'trunk', 'primary', 'secondary', + 'tertiary', 'unclassified', 'residential', + # Link roads + 'motorway_link', 'trunk_link', 'primary_link', 'secondary_link', + 'tertiary_link', + # Special road types + 'living_street', 'service', + 'pedestrian', 'road' # FIXME: Handle predestrian and road differently? +] + +def suitable_car(way): + return way['tags']['highway'] in suitable_highway_types_car diff --git a/templates/index.html b/templates/index.html index b29f84f..00e6208 100644 --- a/templates/index.html +++ b/templates/index.html @@ -8,6 +8,17 @@
+
+ Mode of transport: +
+ + +
+
+ + +
+
Place marker for:
@@ -47,4 +58,4 @@ {{ templates/index.js }} - \ No newline at end of file + diff --git a/templates/index.js b/templates/index.js index 01e3880..42f8398 100644 --- a/templates/index.js +++ b/templates/index.js @@ -19,7 +19,10 @@ async function postShortestPath(event){ if(!lat1 || !lng1 || !lat2 || !lng2) return alert('Formatting Error: Coordinates are not float values.') - req = {lat1, lng1, lat2, lng2} // Dictionary auto-keys + const transport_mode_elem = document.getElementById("transport-mode-bike") + const transport_mode = transport_mode_elem.checked ? "bike" : "car" + + req = {lat1, lng1, lat2, lng2, transport_mode} // Dictionary auto-keys res = await fetch('/shortest-path', { method:'POST', -- cgit v1.2.1 From 4b052bb509b34ff0d6d5bb6d68aacbc469f0f0b0 Mon Sep 17 00:00:00 2001 From: Stefan Hansson Date: Thu, 3 Dec 2020 22:56:07 +0100 Subject: meeep --- algorithms.py | 3 +++ store.py | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/algorithms.py b/algorithms.py index 9d4f538..21d5348 100644 --- a/algorithms.py +++ b/algorithms.py @@ -89,6 +89,9 @@ def get_closest_node_id(nodes, source_node, transport_mode): min_node = node min_value = length + print("min_node: ") + print(min_node) + return min_node diff --git a/store.py b/store.py index 23dc50a..e877eda 100644 --- a/store.py +++ b/store.py @@ -51,8 +51,6 @@ def add_neighbours_bike(nodes): if 'highway' not in way['tags']: continue - print(way) - road = way['road'] for i in range(len(road) - 1): -- cgit v1.2.1 From 7d31854216fd893e1805c6dd40517f329ee3e886 Mon Sep 17 00:00:00 2001 From: Stefan Hansson Date: Tue, 15 Dec 2020 09:34:11 +0100 Subject: wip --- algorithms.py | 2 +- server.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/algorithms.py b/algorithms.py index 21d5348..855c69e 100644 --- a/algorithms.py +++ b/algorithms.py @@ -18,7 +18,6 @@ def length_haversine(p1, p2): return 6372797.560856 * c # return the distance in meters -<<<<<<< HEAD def grid_search(grid, source_node): """ Finds closest node to source node by comparing distance to nodes within @@ -81,6 +80,7 @@ def get_closest_node_id(nodes, source_node, transport_mode): min_value = None for node in nodes: + print(node) length = length_haversine(source_node, node) relevant_neighbours = get_relevant_neighbours(node, transport_mode) diff --git a/server.py b/server.py index 7c89bf6..b928400 100644 --- a/server.py +++ b/server.py @@ -59,11 +59,11 @@ def shortest_path(body): source_id = algorithms.get_closest_node_id(nodes, store.Node(-1, body['lat1'], - body['lng1']) + body['lng1']), transport_mode) target_id = algorithms.get_closest_node_id(nodes, store.Node(-1, body['lat2'], - body['lng2']) + body['lng2']), transport_mode) >>>>>>> 532c0cb... wip -- cgit v1.2.1 From a11a7b4cde5834781aa57e7f9c9a8a3a309d6411 Mon Sep 17 00:00:00 2001 From: Stefan Hansson Date: Wed, 16 Dec 2020 08:06:10 +0100 Subject: wip --- algorithms.py | 11 ++----- server.py | 42 +++++++++++--------------- store.py | 87 ++++++++++++++++++++++++++++++++++++------------------ templates/index.js | 2 +- 4 files changed, 78 insertions(+), 64 deletions(-) diff --git a/algorithms.py b/algorithms.py index 855c69e..3bd9f5e 100644 --- a/algorithms.py +++ b/algorithms.py @@ -73,25 +73,18 @@ def get_closest_node(nodes, source_node): Searches through all nodes in a specified grid and return node closes to source node. """ -def get_closest_node_id(nodes, source_node, transport_mode): - """ Search through all nodes and return the id of the node - that is closest to 'source_node'. """ min_node = None min_value = None for node in nodes: + print(source_node) print(node) length = length_haversine(source_node, node) - relevant_neighbours = get_relevant_neighbours(node, transport_mode) - - if (min_node is None or length < min_value) and relevant_neighbours: + if (min_node is None or length < min_value): min_node = node min_value = length - print("min_node: ") - print(min_node) - return min_node diff --git a/server.py b/server.py index b928400..5992aa2 100644 --- a/server.py +++ b/server.py @@ -4,17 +4,17 @@ import algorithms import store from lib import run_server, get, post, read_html -grid = None +grids = None nodes = None unconnected_nodes = None @get('/') def index(): global nodes - global grid + global grids global unconnected_nodes - nodes, grid, unconnected_nodes = store.extract_osm_nodes("university.osm") + nodes, grids, unconnected_nodes = store.extract_osm_nodes("university.osm") return read_html('templates/index.html') @@ -22,9 +22,10 @@ def index(): @get('/show-area') def show_area(): rect = dict() + # FIXME: Don't hardcode bikes maybe? Maybe just remove this altogether for (k, node) in enumerate( - store.select_nodes_in_rectangle(nodes, 58.3984, 58.3990, 15.5733, - 15.576)): + store.select_nodes_in_rectangle(nodes['bike'], 58.3984, 58.3990, + 15.5733, 15.576)): rect[node.id] = node.coord_tuple() return json.dumps(rect) @@ -41,33 +42,24 @@ def favicon(): @get('/show-unconnected-nodes') def show_unconnected_nodes(): print(f"Showing {len(unconnected_nodes)} unconnected nodes") - return json.dumps({node.id: node.coord_tuple() for node in unconnected_nodes}) + return json.dumps({ + node.id: node.coord_tuple() for node in unconnected_nodes['bike'] + }) @post('/shortest-path') def shortest_path(body): body = json.loads(body) -<<<<<<< HEAD - source_id = algorithms.grid_search(grid, - store.Node(-1, body['lat1'], - body['lng1'])) - target_id = algorithms.grid_search(grid, - store.Node(-1, body['lat2'], - body['lng2'])) -======= transport_mode = body['transport_mode'] - source_id = algorithms.get_closest_node_id(nodes, - store.Node(-1, body['lat1'], - body['lng1']), - transport_mode) - target_id = algorithms.get_closest_node_id(nodes, - store.Node(-1, body['lat2'], - body['lng2']), - transport_mode) ->>>>>>> 532c0cb... wip - - path = algorithms.find_shortest_path(nodes, source_id, target_id, transport_mode) + source_id = algorithms.get_closest_node(grids[transport_mode], + store.Node(-1, body['lat1'], + body['lng1'])) + target_id = algorithms.get_closest_node(grids[transport_mode], + store.Node(-1, body['lat2'], + body['lng2'])) + + path = algorithms.find_shortest_path(nodes[transport_mode], source_id, target_id) response = {"path": [(nodes[node].lat, nodes[node].lng) for node in path]} return json.dumps(response) diff --git a/store.py b/store.py index e877eda..4821072 100644 --- a/store.py +++ b/store.py @@ -7,8 +7,7 @@ class Node: self.id = id self.lat = float(lat) self.lng = float(lng) - self.neighbours_bike = [] - self.neighbours_car = [] + self.neighbours = [] self.parent = None self.size = 1 @@ -46,7 +45,7 @@ class Node: parser = None # Have a global reusable parser object -def add_neighbours_bike(nodes): +def add_neighbours(nodes): for way in parser.iter_ways(): if 'highway' not in way['tags']: continue @@ -57,47 +56,69 @@ def add_neighbours_bike(nodes): node1 = road[i] node2 = road[i + 1] -<<<<<<< HEAD - nodes[node1].neighbours.append(nodes[node2]) - nodes[node2].neighbours.append(nodes[node1]) - # These two are neighbours and should be part of the same tree. - nodes[node1].union(nodes[node2]) -======= - if suitable_car(way): - nodes[node1].neighbours_car.append(nodes[node2]) - nodes[node2].neighbours_car.append(nodes[node1]) - if suitable_bike(way): - nodes[node1].neighbours_bike.append(nodes[node2]) - nodes[node2].neighbours_bike.append(nodes[node1]) ->>>>>>> 532c0cb... wip + bike_nodes = nodes['bike'] - return nodes + bike_nodes[node1].neighbours.append(bike_nodes[node2]) + bike_nodes[node2].neighbours.append(bike_nodes[node1]) + # These two are neighbours and should be part of the same tree. + bike_nodes[node1].union(bike_nodes[node2]) -def add_neighbours_car(nodes): - for way in parser.iter_ways(): - if 'highway' not in way['tags']: - continue + if suitable_car(way): + car_nodes = nodes['car'] + + car_nodes[node1].neighbours.append(car_nodes[node2]) + car_nodes[node2].neighbours.append(car_nodes[node1]) + + # These two are neighbours and should be part of the same tree. + car_nodes[node1].union(car_nodes[node2]) + + return nodes def extract_osm_nodes(f_name): global parser parser = get_default_parser(f_name) - nodes = dict() - grid = defaultdict() + nodes = { + 'bike': dict(), + 'car': dict() + } for node in parser.iter_nodes(): - new_node = Node(node['id'], node['lat'], node['lon']) - nodes[node['id']] = new_node + # FIXME: this can probably be solved better + nodes['bike'][node['id']] = Node(node['id'], node['lat'], node['lon']) + nodes['car'][node['id']] = Node(node['id'], node['lat'], node['lon']) add_neighbours(nodes) + # FIXME: this can probably be solved better # Remove nodes without neighbours - for node_id, node in nodes.copy().items(): - if not node.neighbours_car or not node.neighbours_bike: - del nodes[node_id] + for node_id, node in nodes['bike'].copy().items(): + if not node.neighbours: + del nodes['bike'][node_id] + for node_id, node in nodes['car'].copy().items(): + if not node.neighbours: + del nodes['car'][node_id] + + nodes['bike'], unconnected_bike = make_forest(nodes['bike']) + nodes['car'], unconnected_car = make_forest(nodes['car']) + + unconnected_nodes = { + 'bike': unconnected_bike, + 'car': unconnected_car + } + + grids = { + 'bike': make_grid(nodes['bike']), + 'car': make_grid(nodes['car']) + } + + return nodes, grids, unconnected_nodes + + +def make_forest(nodes): # Construct a forest of disjoint trees. # The forest is a { root: tree }-dict. If we construct a relation where # two nodes relate to each other if they are a part of the same tree, @@ -106,6 +127,7 @@ def extract_osm_nodes(f_name): # becomes the root of each node since it will be the same for all nodes # in the same tree due our use of union-find. forest = defaultdict(dict) + for node_id, node in nodes.items(): forest[node.find_root().id][node_id] = node @@ -129,6 +151,13 @@ def extract_osm_nodes(f_name): unconnected_nodes.append(node) nodes = best_tree + + return nodes, unconnected_nodes + + +def make_grid(nodes): + grid = defaultdict() + # create a "grid" by grouping nearby nodes. for node in nodes.copy().values(): @@ -141,7 +170,7 @@ def extract_osm_nodes(f_name): else: grid[key] = [node] - return nodes, grid, unconnected_nodes + return grid def select_nodes_in_rectangle(nodes, min_lat, max_lat, min_long, max_long): diff --git a/templates/index.js b/templates/index.js index 42f8398..1422fe6 100644 --- a/templates/index.js +++ b/templates/index.js @@ -69,4 +69,4 @@ async function showUnconnectedMarkers() { var marker = L.marker(res[key]).addTo(map) } } -showUnconnectedMarkers() +//showUnconnectedMarkers() -- cgit v1.2.1 From dd50eb5818501eb45cdde745cf239ac12b13a04e Mon Sep 17 00:00:00 2001 From: Stefan Hansson Date: Wed, 16 Dec 2020 09:20:12 +0100 Subject: Implement mode of transport --- algorithms.py | 8 ++------ server.py | 18 +++++++++++------- store.py | 1 + 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/algorithms.py b/algorithms.py index 3bd9f5e..df2f874 100644 --- a/algorithms.py +++ b/algorithms.py @@ -77,8 +77,6 @@ def get_closest_node(nodes, source_node): min_value = None for node in nodes: - print(source_node) - print(node) length = length_haversine(source_node, node) if (min_node is None or length < min_value): @@ -88,7 +86,7 @@ def get_closest_node(nodes, source_node): return min_node -def find_shortest_path(nodes, source_id, target_id, transport_mode: str): +def find_shortest_path(nodes, source_id, target_id): """ Return the shortest path using Dijkstra's algortihm. """ # queue contains multiple (walk_dist, (node_0, node_1, ... node_n))-tuples # where (node_0, node_1, ... node_n) is a walk to node_n @@ -112,9 +110,7 @@ def find_shortest_path(nodes, source_id, target_id, transport_mode: str): # consider all our neighbours end_node = nodes[walk_end] - relevant_neighbours = get_relevant_neighbours(end_node, transport_mode) - - for neighbour in relevant_neighbours: + for neighbour in end_node.neighbours: if neighbour in visited: # there exists a shorter walk to neighbour continue diff --git a/server.py b/server.py index 5992aa2..15145e5 100644 --- a/server.py +++ b/server.py @@ -52,15 +52,19 @@ def shortest_path(body): body = json.loads(body) transport_mode = body['transport_mode'] - source_id = algorithms.get_closest_node(grids[transport_mode], - store.Node(-1, body['lat1'], - body['lng1'])) - target_id = algorithms.get_closest_node(grids[transport_mode], - store.Node(-1, body['lat2'], - body['lng2'])) + relevant_grid = grids[transport_mode] + + source_id = algorithms.grid_search(relevant_grid, + store.Node(-1, body['lat1'], + body['lng1'])) + target_id = algorithms.grid_search(relevant_grid, + store.Node(-1, body['lat2'], + body['lng2'])) + + relevant_nodes = nodes[transport_mode] path = algorithms.find_shortest_path(nodes[transport_mode], source_id, target_id) - response = {"path": [(nodes[node].lat, nodes[node].lng) for node in path]} + response = {"path": [(relevant_nodes[node].lat, relevant_nodes[node].lng) for node in path]} return json.dumps(response) diff --git a/store.py b/store.py index 4821072..34c0f0b 100644 --- a/store.py +++ b/store.py @@ -56,6 +56,7 @@ def add_neighbours(nodes): node1 = road[i] node2 = road[i + 1] + # FIXME: lots of repeated code here if suitable_bike(way): bike_nodes = nodes['bike'] -- cgit v1.2.1 From b965cf506f0614263a0a4884621e439b40cab356 Mon Sep 17 00:00:00 2001 From: Stefan Hansson Date: Wed, 16 Dec 2020 09:24:19 +0100 Subject: remove unused import --- algorithms.py | 1 - 1 file changed, 1 deletion(-) diff --git a/algorithms.py b/algorithms.py index df2f874..7ff395c 100644 --- a/algorithms.py +++ b/algorithms.py @@ -1,6 +1,5 @@ import heapq import math -from store import get_relevant_neighbours def length_haversine(p1, p2): -- cgit v1.2.1 From 1354c8317945ace08145128f03a26ee4e02ddd9e Mon Sep 17 00:00:00 2001 From: Stefan Hansson Date: Wed, 16 Dec 2020 09:25:24 +0100 Subject: Remove redundant changes --- algorithms.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/algorithms.py b/algorithms.py index 7ff395c..f8d2e50 100644 --- a/algorithms.py +++ b/algorithms.py @@ -77,7 +77,6 @@ def get_closest_node(nodes, source_node): for node in nodes: length = length_haversine(source_node, node) - if (min_node is None or length < min_value): min_node = node min_value = length @@ -103,13 +102,10 @@ def find_shortest_path(nodes, source_id, target_id): if walk_end in visited: # there exists a shorter walk to walk_end continue - # otherwise this is the shortest walk to walk_end visited.add(walk_end) # consider all our neighbours - end_node = nodes[walk_end] - - for neighbour in end_node.neighbours: + for neighbour in nodes[walk_end].neighbours: if neighbour in visited: # there exists a shorter walk to neighbour continue -- cgit v1.2.1 From 3af5a89bdefc20ffdc4b66a5ae2a62a8cbabe36c Mon Sep 17 00:00:00 2001 From: Stefan Hansson Date: Wed, 16 Dec 2020 09:26:50 +0100 Subject: More redundant changes removed --- algorithms.py | 3 +-- store.py | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/algorithms.py b/algorithms.py index f8d2e50..9f3fd78 100644 --- a/algorithms.py +++ b/algorithms.py @@ -77,7 +77,7 @@ def get_closest_node(nodes, source_node): for node in nodes: length = length_haversine(source_node, node) - if (min_node is None or length < min_value): + if min_node is None or length < min_value: min_node = node min_value = length @@ -114,6 +114,5 @@ def find_shortest_path(nodes, source_id, target_id): new_dist = walk_dist + length_haversine(nodes[walk_end], neighbour) new_walk = walk + (neighbour.id,) heapq.heappush(queue, (new_dist, new_walk)) - # no path found return None diff --git a/store.py b/store.py index 34c0f0b..2930e19 100644 --- a/store.py +++ b/store.py @@ -128,7 +128,6 @@ def make_forest(nodes): # becomes the root of each node since it will be the same for all nodes # in the same tree due our use of union-find. forest = defaultdict(dict) - for node_id, node in nodes.items(): forest[node.find_root().id][node_id] = node -- cgit v1.2.1 From 3c73ca93fe9896681fb270f0782385b0a9e5d7f1 Mon Sep 17 00:00:00 2001 From: Stefan Hansson Date: Wed, 16 Dec 2020 09:49:02 +0100 Subject: Add more stuff to suitable_bike --- store.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/store.py b/store.py index 2930e19..5ba289b 100644 --- a/store.py +++ b/store.py @@ -195,9 +195,15 @@ def suitable_bike(way): tags = way['tags'] suitable_generic_type = tags['highway'] in suitable_highway_types_bike - suitable_bike = tags['bicycle'] == 'yes' if 'bicycle' in tags else False + suitable_bike = False + # This implies you can go by bike for some reason + is_segregated = 'segregated' in tags - return suitable_generic_type or suitable_bike + if 'bicycle' in tags: + bicycle_tag = tags['bicycle'] + suitable_bike = bicycle_tag == 'yes' or bicycle_tag == 'designated' + + return suitable_generic_type or suitable_bike or is_segregated suitable_highway_types_car = [ -- cgit v1.2.1 From 066929eab31d55573aa7038df1f0be8a6555cfe5 Mon Sep 17 00:00:00 2001 From: Stefan Hansson Date: Wed, 16 Dec 2020 10:19:12 +0100 Subject: Add path to bike highway types --- store.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/store.py b/store.py index 5ba289b..8f25fac 100644 --- a/store.py +++ b/store.py @@ -188,7 +188,9 @@ def get_relevant_neighbours(nodes, transport_mode): suitable_highway_types_bike = [ # Special road types - 'living_street', 'service', 'pedestrian', 'track', 'road' + 'living_street', 'service', 'pedestrian', 'track', 'road', + # ??? + 'path' ] def suitable_bike(way): -- cgit v1.2.1