]> git.xn--bdkaa.com Git - where-are-you.py.git/commitdiff
add objects descriptions from square
authorVladislav Skukov <v.skukov@gmail.com>
Sat, 18 May 2019 15:59:28 +0000 (20:59 +0500)
committerVladislav Skukov <v.skukov@gmail.com>
Sat, 18 May 2019 15:59:28 +0000 (20:59 +0500)
osm/osm.py [new file with mode: 0644]

diff --git a/osm/osm.py b/osm/osm.py
new file mode 100644 (file)
index 0000000..194af89
--- /dev/null
@@ -0,0 +1,29 @@
+from osmapi import OsmApi
+import pprint
+
+Api = OsmApi()
+
+min_lon, min_lat, max_lon, max_lat = 60.5906827939,56.8322320824,60.5942769539,56.834157283
+
+
+def get_objects_from_square(min_lon, min_lat, max_lon, max_lat):
+    objects = Api.Map(min_lon, min_lat, max_lon, max_lat)
+    return list(filter(lambda o: 
+    o['data']['tag'] != {}
+    and 'lat' in o['data']
+    and 'lon' in o['data']
+    and 'amenity' in o['data']['tag']
+    and 'name' in o['data']['tag'], objects))
+
+def describe_objects(min_lon, min_lat, max_lon, max_lat):
+    objects =  [
+      {'name': x['data']['tag']['name'],
+       'lat': x['data']['lat'],
+      'lon': x['data']['lon']} for x in get_objects_from_square(min_lon, min_lat, max_lon, max_lat)]
+    return {'center': {'lat': (min_lat + max_lat) / 2, 'lon': (min_lon + max_lon) / 2},
+            'objects': objects}
+
+
+objects = describe_objects(min_lon, min_lat, max_lon, max_lat)
+print(objects)
\ No newline at end of file