diff options
| author | Stefan Hansson <steha708@edu.liu.se> | 2020-11-05 15:10:55 +0100 |
|---|---|---|
| committer | Newbyte <steha708@liu.se> | 2020-11-05 15:10:55 +0100 |
| commit | d429f09e7e3bc8173e765aba8a91f2440c99a324 (patch) | |
| tree | df0d6466bad2fabc4412b0e352fc197f97a343fa /store.py | |
| parent | 6054b37c778ba6ea9d816bb9885513c19917a372 (diff) | |
| download | tdde25-d429f09e7e3bc8173e765aba8a91f2440c99a324.tar.gz | |
Implement finding nearest nodes to start and end positions
Diffstat (limited to 'store.py')
| -rw-r--r-- | store.py | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -6,22 +6,45 @@ class Node: self.id = id self.lat = float(lat) self.lng = float(lng) + self.neighbors = [] + def coord_tuple(self): return self.lat, self.lng parser = None # Have a global reusable parser object +nodes = None + + +def add_neighbours(nodes): + for way in parser.iter_ways(): + if 'highway' not in way['tags']: + continue + + road = way['road'] + + for i in range(len(road) - 1): + node1 = road[i] + node2 = road[i + 1] + + nodes[node1].neighbors.append(nodes[node2]) + nodes[node2].neighbors.append(nodes[node1]) + + return nodes def extract_osm_nodes(f_name): global parser + global nodes parser = get_default_parser(f_name) nodes = dict() for node in parser.iter_nodes(): nodes[node['id']] = Node(node['id'], node['lat'], node['lon']) + add_neighbours(nodes) + return nodes |
