4

I try to get the geocodes coordinates from the location(nominatim) into the Overpass query.

Is there an easy way to do this?

import json
import requests
from geopy.geocoders import Nominatim

geolocator = Nominatim(user_agent="your_app_name")
location = geolocator.geocode("Hufnerstraße 1, Hamburg")

lat = location.latitude
lng = location.longitude

print(lat, lng)

overpass_url = "http://overpass-api.de/api/interpreter"

overpass_query = """
[out:json];
(node["shop"](around:500,53.59057989074252,10.05931163368573);
        );out;
"""

response = requests.get(overpass_url, params={'data': overpass_query})
data = response.json()

print(response.json())

1 Answer 1

4

Since the overpass_query is just a string, you can use string formatting:

overpass_query = f"""
[out:json];
(node["shop"](around:500,{lat},{lng});
        );out;
"""

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.