sync: 2026-08-21 15:04:46

This commit is contained in:
2026-08-21 15:04:46 +02:00
parent 26d9a0dcf7
commit 6d7709e008
3 changed files with 579 additions and 87 deletions

67
app.py
View File

@@ -17,6 +17,70 @@ last_request_time = 0
MIN_REQUEST_INTERVAL = 1.0
def classify_place(item):
"""
Classify a Nominatim result into one of:
- "area" : countries, states, cities, towns, villages, suburbs,
neighbourhoods, water bodies, natural features, etc.
- "poi" : shops, restaurants, hotels, buildings, attractions, ...
- "address" : street / house-number level results
- "other" : anything else
The client uses this to pick an appropriate zoom level when the
user selects a result.
"""
category = (item.get("category") or "").lower()
place_type = (item.get("type") or "").lower()
address = item.get("address") or {}
namedetails = item.get("namedetails") or {}
# Administrative boundaries are always areas.
if place_type.endswith("_boundary"):
return "area"
# Place categories (city, town, village, suburb, ...) are areas.
if category == "place":
return "area"
# Boundaries are areas.
if category == "boundary":
return "area"
# Natural & water features are treated as areas (they span regions).
if category in ("natural", "water", "waterway"):
return "area"
# A real street/house-number result is an address.
if (
address.get("house_number")
or address.get("road")
):
if (
namedetails.get("name")
or namedetails.get("addr:housenumber")
or address.get("house_number")
):
return "address"
# Known POI categories.
poi_categories = {
"amenity",
"shop",
"tourism",
"leisure",
"office",
"craft",
"building",
"historic",
"industrial",
"public_transport",
}
if category in poi_categories:
return "poi"
return "other"
def nominatim_request(url, params):
"""
Make a request to Nominatim while respecting a small
@@ -124,6 +188,9 @@ def search():
"category":
item.get("category"),
"kind":
classify_place(item),
"address":
item.get("address", {}),