About the NameFinder or Geocoding in OSM


When we type a street name in the Search area of http://www.openstreetmap.com/, then we can get a list of address, which are the cities including the typed street.
Does it mean that OSM has such a **database **as shown below, based on which OSM service can find the corresponding city and country of a given street name, right?

CountryName,    CityName,     StreetName
Sweden,            Stockholm,    Vasagatan
Sweden,            Stockholm,    Sveavägan
...                      ...                 ...

Sweden, Uppsala, Kungsgatan
… … …

I am not sure whether this kind of dataset exists, and the accessibity of it. If I want to find out the city and country a named street belongs, how can I do it based on my own algorithm and OSM dataset? (In OSM data, the name tag does not include the city name as well as country name)

Similarly, given a point (latitude, longitude), how can I efficiently find out which street the point is closest to? In doing this, we need a spatial index for OSM data. For instance, we need to know how many cities a country has, and the boundary of every city. Based on these, we can position the point in a city according to the city’s boudary, and then we can find the street closest to the given point quickly. Am I right? If so, does such a dataset exist?

CountryName,    CityName,     Boundary
Sweden,            Stockholm,    ([x0 y0], [x1 y1], [x2 y2] ...)
Sweden,            Uppsala,        ([x0 y0], [x1 y1], [x2 y2] ...)
...                      ...                ...

Many thanks in advance!


No such DB, the search box (which is called namefinder) does this by getting the closest city node. Areas are not available either, the best place to get these would be wikimapia but it isn’t copyleft friendly.

You should ofcourse use a spatial database if you want to do these things with openstreetmap, there are instructions on how to install postgis on the wiki. http://wiki.openstreetmap.org/wiki/Mapnik

Hi emj, thanks for your reply and help. I will refer to the postgis later. Thank you.

Hi emj, I am sorry, but I still want to figure it out that, given a street name, how OSM get the city names that include the given street? For instance, give an street named Kungsgatan, the cities which include Kungsgatan may be Stockholm, Uppsala, Gävle and etc. You said that OSM does this by getting the closest city node. Could you please give some details about it? E.g what is the city node, and how to access it?

Thanks a lot.


city node is a node tagged with
place=city; name=Stockholm
place=suburb; name=165 dags att hitta hem

Read more about name finder, it uses insanely complicated php code to parse the planet.osm and dump it to a custom databse which then is used to give you these results.