summaryrefslogtreecommitdiffstats
path: root/store.py
diff options
context:
space:
mode:
Diffstat (limited to 'store.py')
-rw-r--r--store.py62
1 files changed, 59 insertions, 3 deletions
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