I'm trying to retrieve a hierarchical list administrative areas that "contain" a certain node.

For example, if I have a node that has the tag "street" with the name "Sukhumvit", then I want to find the neighborhood, sub-district, district, city, province, state, higher level administrative areas, and country who's boundaries contain this node.

More specifically, in the case of Sukhumvit (a street in Thailand), it would have to return things nodes with the tag neighborhood (name=Sukhumvit), district (name=Watthana District), city (name=Bangkok), country (name=Thailand), and more.

Is it possible to retrieve all nodes with pre-specified tags that have geographic boundaries surrounding a certain latitude and longitude position? I'm willing to import OSM data into solutions like ElasticSearch if that helps.

asked 09 May '14, 08:12

TomM's gravatar image

TomM
41346
accept rate: 0%


You have already been told that re-inventing Nominatim will be a lot of work. I hope that you don't expect us to re-invent Nominatim for you on this platform ;)

First of all, streets are not usually represented by nodes, but by ways. You do not have "a node that has the tag street with the name Sukhumvit". You have a way with the tag highway and the name Sukhumvit, and that way will be built from nodes, which have a location.

Then, nodes don't have geographic boundaries so your question does not make sense. What you are looking for is administrative boundaries which may be given in the form of a single, closed way, or, more commonly, a multipolygon relation. Existing SQL database importers like osm2pgsql (used by Nominatim) or imposm will resolve these into proper polygons for you, as will the Osmium C++ library. You can also do this yourself but that would mean reinventing another type of wheel, as constructing polygons from the OSM data is not trivial.

Once you have these polygons, you can use geometric operations to find out which of them enclose your polygon. Again, PostGIS (used by Nominatim) can do this, and is indeed used by Nominatim to build such a hierarchy like the one you're looking for. Alternatively, you can use libraries like GEOS for C/C++ or its bindings in various scripting languages. Doing this efficiently will require building indexes.

But aside from the polygons, you will still want to look at single nodes that do not enclose the position you are interesed in, but are just in the vicinity - for example, there might be a node tagged "place=neighbourhood, name=Sukhumvit", which simply sits somewhere in the vicinity of the street that you are looking for, and you have to apply heuristics to determine whether or not your street should be counted as belonging to that neighbourhood. Again, this is something that Nominatim already does.

Are you sure you still want to build your own geocoder?

permanent link

answered 09 May '14, 08:54

Frederik%20Ramm's gravatar image

Frederik Ramm ♦
70.7k826421105
accept rate: 24%

I read ElasticSearch's documentation and was under the impression that querying for locations within such administrative boundaries was trivial using their solution. The reason I am hesitant to use Nominatim is that it doesn't seem to accomodate for partial-match full-text search, because when I search for "Sukhumvit 21 11th Flr." it doesn't return anything, while "Sukhumvit 21" does. ElasticSearch seems more capable of searching for partial matches. I like Photon, but it is not useful for me because it doesn't return any administrative areas (https://github.com/komoot/photon/issues/30)

(09 May '14, 09:09) TomM
1

Maybe you can get in touch with the people behind Pelias. See video at State of the Map US 2014 http://stateofthemap.us/session/pelias/ they use Elastic Search for reverse Geocoding

(09 May '14, 09:26) escada

an entry about Pelias was missing in the OSM wiki about http://wiki.openstreetmap.org/wiki/Search_engines ... done

(09 May '14, 15:09) stephan75
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×165
×113
×101
×49

question asked: 09 May '14, 08:12

question was seen: 8,546 times

last updated: 09 May '14, 15:09

powered by OSQA