Selaa lähdekoodia

Add default names of places

Marcin Jaborski 3 vuotta sitten
vanhempi
sitoutus
d34255232f
2 muutettua tiedostoa jossa 24 lisäystä ja 18 poistoa
  1. 11 5
      scripts/fetch_places.py
  2. 13 13
      scripts/map features.txt

+ 11 - 5
scripts/fetch_places.py

@@ -1,5 +1,6 @@
 import requests
 import json
+import pygeohash as pgh
 from google.cloud import firestore
 
 import os
@@ -15,24 +16,29 @@ with open('map features.txt', 'r') as f:
     for line in f:
         if line[0] == "#":
             continue
+        category, category_name = line.split(":")
+        category_name = category_name.replace("\"", "").strip()
         overpass_query = f"""
 [out:json];
 area["ISO3166-1"="PL"][admin_level=2];
-node[{line[:-1]}](area);
+node[{category}](area);
 out center;
 """
         response = requests.get(overpass_url, params={"data": overpass_query})
         try:
             elements = response.json()["elements"]
         except json.JSONDecodeError:
-            print(f"Could not decode data for {line[:-1]}")
+            print(f"Could not decode data for {category}")
             continue
-        object_type = line.split("=")[1].strip()
+        object_type = category.split("=")[1].strip()
         data = {}
         for el in elements:
             try:
-                data["name"] = el["tags"].get("name", object_type)
-                data["location"] = firestore.GeoPoint(el["lat"], el["lon"])
+                data["name"] = el["tags"].get("name", category_name)
+                data["location"] = {
+                    "geohash": pgh.encode(el["lat"], el["lon"], precision=9),
+                    "geopoint": firestore.GeoPoint(el["lat"], el["lon"])
+                }
                 data["category"] = object_type
                 batch.set(db.collection("Places").document(str(el["id"])), data)
                 count += 1

+ 13 - 13
scripts/map features.txt

@@ -3,17 +3,17 @@
 #amenity=college
 #amenity=library
 #amenity=university
-#amenity=arts_centre
-#amenity=community_centre
-#amenity=fountain
+amenity=arts_centre:"Arts centre"
+amenity=community_centre:"Community centre"
+amenity=fountain:"Fountain"
 #amenity=planetarium
 #amenity=public_bookcase
-#amenity=social_centre
+amenity=social_centre:"Social centre"
 #amenity=theatre
 #amenity=townhall
 #amenity=bbq
-#amenity=clock
-#boundary=forest
+amenity=clock:"Clock"
+boundary=forest:"Forest"
 #building=cathedral
 #building=chapel
 #building=church
@@ -30,13 +30,13 @@
 #historic=memorial
 #historic=monument
 #historic=ruins
-#leisure=dog_park
-#leisure=park
-#tourism=artwork
-#tourism=attraction
+leisure=dog_park:"Dog park"
+leisure=park:"Park"
+tourism=artwork:"Artwork"
+tourism=attraction:"Attraction"
 #tourism=gallery
 #tourism=museum
-#tourism=picnic_site
+tourism=picnic_site:"Picnic site"
 #tourism=theme_park
-#tourism=view_point
-#tourism=zoo
+tourism=view_point :View point"
+tourism=zoo:"Zoo"