Search around a line
Since version 0.7.55 the around filter takes a list of points: (around:radius,lat1,lon1,lat2,lon2,…) finds what lies within the radius, in metres, of the line through them. Latitude comes first.
[out:json][timeout:25];
node["amenity"="drinking_water"](around:150,46.2044,6.1432,46.1990,6.1500,46.1900,6.1520);
out;
This query asks for drinking water within 150 m of a three-point line through Geneva. Our endpoint answered it with 14 taps in 0.3 seconds.
From a GPX file to a list with kilometres
A GPX track has a point every few metres, and a query with thousands of coordinates is long and slow. The script keeps a point every 250 m, sends one query, and gives each place the kilometre of the nearest kept point. It needs pip install requests gpxpy.
import math
import sys
import gpxpy
import requests
OVERPASS_URL = "https://overpass-api.de/api/interpreter"
HEADERS = {"User-Agent": "my-ride-planner/1.0"}
def track_points(path):
"""Every point of every track in a GPX file, as (lat, lon)."""
with open(path) as f:
gpx = gpxpy.parse(f)
return [(p.latitude, p.longitude)
for track in gpx.tracks for segment in track.segments for p in segment.points]
def metres(a, b):
"""Distance between two (lat, lon) points in metres."""
lat1, lon1, lat2, lon2 = map(math.radians, (*a, *b))
h = math.sin((lat2 - lat1) / 2) ** 2 + math.cos(lat1) * math.cos(lat2) * math.sin((lon2 - lon1) / 2) ** 2
return 2 * 6371000 * math.asin(math.sqrt(h))
def thin(points, step_m):
"""Keep a point every step_m metres, with the distance from the start of each."""
kept, along, last = [(points[0], 0.0)], 0.0, points[0]
for p in points[1:]:
along += metres(last, p)
last = p
if along - kept[-1][1] >= step_m:
kept.append((p, along))
if kept[-1][0] != points[-1]:
kept.append((points[-1], along))
return kept
def overpass_query(line, radius_m):
coords = ",".join(f"{lat:.5f},{lon:.5f}" for (lat, lon), _ in line)
return f"""[out:json][timeout:90];
(
nwr["amenity"="drinking_water"](around:{radius_m},{coords});
nwr["drinking_water"="yes"](around:{radius_m},{coords});
);
out center;"""
def water_along(path, radius_m=100, step_m=250):
line = thin(track_points(path), step_m)
response = requests.post(OVERPASS_URL, data={"data": overpass_query(line, radius_m)}, headers=HEADERS, timeout=120)
response.raise_for_status()
places = []
for element in response.json()["elements"]:
where = (element["lat"], element["lon"]) if "lat" in element else (element["center"]["lat"], element["center"]["lon"])
# The nearest kept point gives the kilometre, to within half a step.
(_, km) = min(((metres(where, p), along) for p, along in line))
places.append((km / 1000, element["tags"].get("name", ""), element["type"], element["id"]))
return sorted(places)
if __name__ == "__main__":
for km, name, kind, osm_id in water_along(sys.argv[1]):
print(f"{km:6.1f} km {kind}/{osm_id} {name}")
On a 42 km bike route from Geneva to Annecy, sent to our endpoint (it takes the same query), it found 23 places with drinking water:
python water_along_track.py ride.gpx
0.0 km node/6597445539
1.9 km node/4426603391 rue des Allobroges
25.5 km node/11059601131
36.3 km node/8291624277
...
- The kilometre is that of the nearest kept point, so it can be off by up to half a step, 125 m here. For exact marks, project each place onto the full track.
- On winding roads a 250 m step cuts the corners of hairpins. Keep more points (a smaller
step_m) or use a larger radius. out centergives ways and relations one point, so a fountain mapped as an area still gets a kilometre.
Which tags to ask for
Replace the two lines inside the parentheses of the query with the tags of what you need. These are the usual ones in OpenStreetMap:
| What | Tags |
|---|---|
| Drinking water | amenity=drinking_water, and drinking_water=yes on fountains and taps |
| Food | amenity=cafe, restaurant, fast_food; shop=bakery |
| Groceries | shop=supermarket, convenience |
| Toilets | amenity=toilets |
| Bike repair | shop=bicycle, amenity=bicycle_repair_station |
Long tracks and the public server
A long track makes a long query and a long run. On overpass-api.de a query that declares more time than the server has free is refused with 504, and all requests from one IP address share a few slots. Split a long track into pieces of, say, 50 km and send them one after another, not at once.
Since April 2026 the public server also refuses some requests outright with 406, for example those with the default User-Agent of Python’s requests, which is why the script sets its own. The Overpass errors guide explains 429, 406 and 504 and what to change.
The same in one request with our API
POST /v1/route-poi/corridor takes the track as points with their distance from the start, and answers with each place’s kilometre and its distance from the route, plus the stretches of more than 40 km without water and food. This uses track_points and thin from the script above:
import os
import sys
import requests
from water_along_track import thin, track_points
KEY = os.environ["RUNNING_CAT_KEY"]
points = thin(track_points(sys.argv[1]), step_m=100)
if len(points) > 1000:
points = thin(track_points(sys.argv[1]), step_m=points[-1][1] / 999)
body = {
"points": [{"lat": lat, "lon": lon, "d": round(d)} for (lat, lon), d in points],
"categories": ["water", "food", "toilets"],
}
response = requests.post("https://geo.runningcat.dev/v1/route-poi/corridor", json=body,
headers={"Authorization": f"Bearer {KEY}"}, timeout=60)
response.raise_for_status()
answer = response.json()
for poi in answer["pois"]:
print(f'{poi["distanceAlongRouteKm"]:6.1f} km {poi["category"]:8} {poi["subtype"]:16} {poi["name"] or ""} ({poi["offsetFromRouteM"]} m off)')
for gap in answer["gaps"]:
print("No water or food:", gap)
It takes up to 1,000 points, so the script thins a long track to fit. The categories are water, food, groceries, toilets, bike shops, fuel and a few more, each with its own distance from the route, up to 5 km. POI along a route has the details; the free plan gives 500 requests a day.
Sources: Overpass QL on the OpenStreetMap wiki, the around filter, read on 16 November 2026. The examples ran against geo.runningcat.dev on the same day.