Search code examples
openstreetmapoverpass-api

Overpass-turbo: add city name to a specific node


I'm requesting some drinking_water nodes by id:

node(id:1560728638,
1560728638,
1835271176,
1844271135
    ); out body;

I'd like to request the name of the city where the nodes are, for example:

osm_id city
1560728638 city A
1560728638 city A
1835271176 city B
1844271135 city C

Is it possible?


Solution

  • In your case, the nodes already have a city tag: "addr:city"

    You can ask and search question about overpass, OSM and various geographic queries on gis.stackexchange.com, it might be more focused that here.

    Anyway, you can run the following query on overpass turbo:

    // output to .csv file, with columns
    [out:csv(::type,::id,amenity, name, "addr:city")];
    // list of nodes
    node(id:1560728638,
    1560728638,
    1835271176,
    1844271135
        );
    
    //for each node:
    // print the node,
    // then get the surrounding (is_in),
    // filter that for cities (admin_level 8),
    // and return they city
    
     foreach->.d(
      .d out;   
      .d is_in;
      area._[admin_level~"[8]"];
     out;
       );
    

    So you get a list of your original nodes (in a different order), and the city they're in. They you can just extract the data from the file o put in in the format you want:

    @type @id amenity name addr:city
    node 1835271176 drinking_water Privas
    area 3600087515 Privas
    node 1560728638 drinking_water Privas
    area 3600087515 Privas
    node 1844271135 drinking_water Saint-Etienne-de-Serre
    area 3602084772 Saint-Étienne-de-Serre