How to debug missing nominatim results?

Hi,

I’m using OSM to optimize a somewhat lenghty roadtrip around southern Europe. Waypoint names (exclusively Tesla Superchargers) are fed into a local script that pulls GPS coordinates via nominatim, stores these to a local JSON file, and then I do things with it. Most of my waypoints do work right away, some just had not enough data on OSM so I’ve added and expanded these entries, some need a bit of rework on my side for whatever reason (e.g. removal of the country, which is part of the supercharger name), and some still cannot be found despite suitable (?) edits.

The number of duds is pretty small, so I could just get away with manually pulling GPS coordinates and edit my local cache, but I’d like to understand why that happens and if I can work around or improve things, so that other people can pull correct data in the future.

These are the four waypoints that I cannot get OSM to locate:

Supercharger Nîmes, France – Nimotel: OpenStreetMap / www.tesla. com/en_eu/findus?location=Self-ServeDemoDrive
Supercharger Aire des Portes d’Angers, France: OpenStreetMap / www.tesla. com/en_eu/findus?location=portesdangerssupercharger
Supercharger Saint-Pierre-d’Irube, France: OpenStreetMap / www.tesla. com/en_eu/findus?location=30243
Supercharger Aire de Vidauban Sud, France: www.openstreetmap. org/#map=19/43.413961/6.451190 / www.tesla. com/en_eu/findus?location=vidaubanfrsupercharger
(you need to fix these links yourself, a new user can only add three… :roll_eyes:)

The Nimotel one can be found by omitting the Supercharger part, which is a) a special case since few locations are tagged with street names or other POI, and b) if searching for the actual Nimotel hotel nearby, it cannot be found, as OSM only references the charging station.
An example where searching for the full street name fails would be “(Supercharger) Offenburg, Germany - Wilhelm-Röntgen-Straße” - this only resolves when omitting the “Germany” part, although the street name should be known to OSM. Having the country name in literally over 100 other queries works perfectly fine, but this one refuses to resolve once Germany is mentioned. Removing the country can lead to other issues, e.g. with Supercharger Orange, France and Supercharger Saint-Louis, France, when Orange and Saint-Louis are located in the US instead.

So my question would be how to debug this and find the “correct” name or combination of fields to populate without making tons of experimental edits and database queries..?

MWE (python code)
# Requirements: pip install geopy folium tqdm

from geopy.geocoders import Nominatim
from geopy.extra.rate_limiter import RateLimiter
import folium
from tqdm import tqdm
import json
import os

places = [
"Supercharger Füssen, Germany",
"Supercharger St. Anton, Austria",
"Supercharger Schaan, Liechtenstein",
"Supercharger Bressanone, Italy",
"Supercharger Aix-en-Provence, France - Beaumanoir",
"Supercharger Xinzo de Limia, Spain",
"Supercharger Fátima, Portugal",

"Supercharger Offenburg, Germany – Wilhelm-Röntgen-Straße",
"Supercharger Valencia, Spain – Paterna",
"Supercharger Nîmes, France – Nimotel",
"Supercharger Aire des Portes d'Angers, France",
"Supercharger Saint-Pierre-d'Irube, France",
"Supercharger Aire de Vidauban Sud, France"
]

geolocator = Nominatim(user_agent="southern_europe_route_map")
geocode = RateLimiter(geolocator.geocode, min_delay_seconds=1, swallow_exceptions=True)

CACHE_FILE = "geocode_cache.json"

if os.path.exists(CACHE_FILE):
    with open(CACHE_FILE, "r", encoding="utf-8") as f:
        cache = json.load(f)
else:
    cache = {}

def resolve_place(name):
    if name in cache:
        return cache[name]
    result = geocode(name)
    if result is None:
        simplified = name.split(" - ")[0].replace("Northbound", "").replace("Route Nationale", "").strip()
        result = geocode(simplified)

    if result:
        cache[name] = {"lat": result.latitude, "lon": result.longitude}
        with open(CACHE_FILE, "w", encoding="utf-8") as f:
            json.dump(cache, f, ensure_ascii=False, indent=2)
        return result
    else:
        cache[name] = None
        with open(CACHE_FILE, "w", encoding="utf-8") as f:
            json.dump(cache, f, ensure_ascii=False, indent=2)
        return None

coords = []
for p in tqdm(places, desc="Geocoding"):
    r = resolve_place(p)
    if r is not None:
        coords.append((r["lat"] if isinstance(r, dict) else r.latitude,
                       r["lon"] if isinstance(r, dict) else r.longitude))
m = folium.Map(location=[43, 0], zoom_start=6, tiles="OpenStreetMap")

for lat, lon in coords:
    folium.CircleMarker(
        location=[lat, lon],
        radius=3,
        color="#1f6feb",
        fill=True,
        fill_color="#1f6feb",
        fill_opacity=0.9
    ).add_to(m)

folium.PolyLine(coords, color="#d73a49", weight=2, opacity=0.9).add_to(m)

m.save("southern_europe_route.html")

2 Likes

Hi @Bzzz and welcome here!

To debug nominatim seach, simply type your search terms into the main as in Supercharger Offenburg | OpenStreetMap

and then click “Nominatim”.

But I think you should not use nominatim at all, you should use Overpass, see Search - Nominatim 5.2.0 Manual

And it’s not a good idea to misuse the name tag to get the results you want.

3 Likes

Nominatim can’t find names that have a comma in them. It just seems to work most of the time because the “name” is actually a location description which happens to correspond to what Nominatim assembles as the address of the supercharger. And that in turn only works if the country name happens to come at the end.

2 Likes

Searching for “Nimotel” returns both the charging station and the hotel as shown in this screenshot. It’s a minor point but might help clarify your understanding.

That’s a lot of responses in a very short amount of time, thank you guys!

Well aside from running into “Error contacting nominatim.openstreetmap. org: 503” more often than not, this is just a more direct way to query things, like running the script in debug mode. I still don’t know why this runs fine:

with the place name set to “Supercharger Lodi, Italy”, and this one returns no results

with the place name set to “Supercharger Aire de Vidauban Sud, France”
A literal full match on the place name should work for both of these.

If that is true, that’s valueable information! Will test if some script-side reformatting of the country names will help

That is true for searching “Nimotel”. That is not true for searching “Nîmes, France – Nimotel”, but maybe the comma thing comes into play here. Searching without the comma does present both results once more…

1 Like

It seems to work using the structured input at nominatim.openstreetmap.org, at least for this example, although I don’t know if that will always be the case.

I doubt many people would search for a hotel in that format.

These charging points are unusual in the name tag having something that looks like a partial address. For almost any other kind of POI, adding “,France” in the name tag would be considered redundant. It’s not surprising that it’s a little tricky to work with.

2 Likes

I played with the structured search fields in a former project, but there’s always some outlier that doesn’t fit the thing, so I run multi-stage queries until something sticks. For me, that wasn’t worth the effort here, I just wanted to understand why a search for a full string that is literally placed as the name of a point doesn’t match in these four cases.

So: Just removing the comma indeed worked for my full list of 157 charging stops, without exception :star_struck:

1 Like

Allow me to be a bit more direct here: I strongly disagree with the name changes you have made to these stations, adding a comma-separated country to the name. There is no indication on the Tesla website that these chargers even have an official name. Those websites just need a heading and the approximate location is as good as any to distinguish the locations.

5 Likes

Here’s a quick overview of most supercharger stations that I have personally visited. Most of them contain, comma-separated, the country of that station, despite pretty much all of the customers being able to tell which country they’re currently in. Together with the heading of the respective websites being the same, I’d say that’s evidence that this is the official name of the location and not just a made-up thing.

(4096x4010 px resolution, in my preview window the forum software resizes this 2:1 without asking)


Copy on Twitter: https://pbs.twimg.com/media/G3n7O7rXEAAGEKV?format=jpg&name=4096x4096

If commas pose a serious problem, users shouldn’t be able to insert them in the first place..?