summaryrefslogtreecommitdiffstats
path: root/store.py
diff options
context:
space:
mode:
authorMax Bringemo <maxbr167@student.liu.se>2020-11-02 15:54:52 +0100
committerMax Bringemo <maxbr167@student.liu.se>2020-11-02 15:54:52 +0100
commit5a25e55b0fd59a032c4c85af452bd433427c3890 (patch)
tree84252877002e3eec3f58f92d614c225557a21156 /store.py
parent58f04e8c6d768fc8b912ec1af44442eebac03595 (diff)
downloadtdde25-5a25e55b0fd59a032c4c85af452bd433427c3890.tar.gz
finished introductory phase
Diffstat (limited to 'store.py')
-rw-r--r--store.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/store.py b/store.py
index e69de29..3d91f5b 100644
--- a/store.py
+++ b/store.py
@@ -0,0 +1,32 @@
+from osm_parser import get_default_parser
+
+
+class Node:
+ def __init__(self, id, lat, lng):
+ self.id = id
+ self.lat = float(lat)
+ self.lng = float(lng)
+
+ def coord_tuple(self):
+ return self.lat, self.lng
+
+
+parser = None # Have a global reusable parser object
+
+
+def extract_osm_nodes(f_name):
+ global parser
+ parser = get_default_parser(f_name)
+ nodes = dict()
+
+ for node in parser.iter_nodes():
+ nodes[node['id']] = Node(node['id'], node['lat'], node['lon'])
+
+ return nodes
+
+
+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]
+