I am trying to query multiple categories on Overpass (to later do analysis on categories). The query is embedded in a streamlit application and works with a bounding box derived from a folium map. I can see all POIs from the amenity key but the other keys get sometimes like 4 responses or nothing at all on any bounding box I tried. But at least there should be tons of buildings. Therefore the error must be somewhere here in this code:
### DATA
buildings = ["yes"]
transportation_public_transport = ["platform"]
religion_amenity = ["place_of_worship"]
shopping_amenity = ["supermarket", "convenience", "grocery"]
shopping_publicservice_amenity = ["bank", "post_office", "post_box", "atm"]
healthcare_amenity = ["clinic", "dentist", "doctors", "hospital", "pharmacy"]
healthcare_recreation_leisure = ["park", "garden"]
healthcare_recreation_landuse = ["recreation_ground", "forest"]
healthcare_sport_leisure = ["fitness_centre", "fitness_station"]
healthcare_sport_sport = ["*"]
healthcare_sport_club = ["sports"]
kids_amenity = ["kindergarten", "school", "childcare"]
highereducation_amenity = ["university", "college"]
entertainment_amenity = ["restaurant", "fast_food", "cafe", "bar", "pub", "ice_cream", "night_club", "biergarten"]
entertainment_leisure = ["swimming_pool", "playground"]
entertainment_culture_amenity = ["community_centre", "library", "theatre", "cinema", "arts_centre", "events_venue"]
### DATA FETCHING
def fetch_pois(sw_lat, sw_lng, ne_lat, ne_lng):
"""Fetch POIs (Points of Interest) from OSM using the Overpass API."""
overpass_url = "http://overpass-api.de/api/interpreter"
# Define the key-value pairs
key_value_pairs = {
"amenity": (
religion_amenity +
shopping_amenity +
shopping_publicservice_amenity +
healthcare_amenity +
kids_amenity +
highereducation_amenity +
entertainment_amenity +
entertainment_culture_amenity
),
"public_transport": transportation_public_transport,
"leisure": healthcare_recreation_leisure + entertainment_leisure,
"landuse": healthcare_recreation_landuse,
"sport": healthcare_sport_sport,
"club": healthcare_sport_club,
"building": buildings,
}
nodes = "n".join(
f'node["{key}"="{value}"]({sw_lat},{sw_lng},{ne_lat},{ne_lng});'
for key, values in key_value_pairs.items()
for value in values
)
overpass_query = f"""
[out:json];
(
{nodes}
);
out body;
"""
response = requests.get(overpass_url, params={"data": overpass_query})
return response