Search code examples
openstreetmapoverpass-api

Grouped nodes in OpenStreetMap with Overpass API


Hy.I would like to query nodes gruped by some area. For example: how to get all nodes (e.g. peaks) for given area (eg. administrative boundary - country).

Something like join in SQL: SELECT n.*, a.name from node n LEFT JOIN area a ON n.area_id = a.id WHERE n.type = "peak"

Resoult would be something like:

{ features: [
 { 
   type: "node:",
   area: "slovenia"
   properties: {....},
   geometry: {...}
 },
 ...
]}

or maybe:

{ areas: [
 slovenia: {
  nodes: [
  { 
   type: "node:",
   area: "slovenia"
   properties: {...},
   geometry: {...}
  },
  ...
  ]
 },
 ...
]}

Is this even possible? Or should I first make 1 query for all areas and then for each area make another query?


Solution

  • Area in area support is not yet officially available (see this Github pull request for some ideas how this might look like in the future), but you could use the approach described on the following help page:

    https://help.openstreetmap.org/questions/35976/add-reverse-geocoding-information-to-the-overpass-resulting-set

    In particular I'd recommend to take a look at the following query: http://overpass-turbo.eu/s/4FJ

    It works with a single query but mixes sign posts with all areas this sign post is included.You should be able to easily adjust this to your tags / area. Note that a bit of post processing on the result may be required.

    Probably the closest thing you're looking for is also described in the Github pull request. This would print the area followed by all nodes in that area. But as I mentioned, this will only be available at some point in the future.

    Sample output:

    @oname  @id     name
    area    3600062387      Landkreis Merzig-Wadern
    node    313138635       
    node    313150002       
    node    313460474       
    node    315050154       
    node    431311279       
    ...