pythonopenstreetmapoverpass-api

Overpass querying places of interest by city


I'm new to Overpass and OpenstreetMap. I'm working on a project and I need to fetch the places of interest for New York City (for now, in the future it should be generic to handle any kind of city).

I'm writing this query in python using the overpass api but I'm not sure how to do it. I tried to do

[out:json];
area["name"="New York City"]->.nyc;
(
  node(area.nyc)["amenity"];
  way(area.nyc)["amenity"];
  relation(area.nyc)["amenity"];
);
out center;

but this doesn't work. The following works but a - its overkill, I only need it for NYC, not the NY state.

          [out:json];
          area[{"ISO3166-2"="US-NY"}][admin_level=4];
          (
            node["amenity"](area);
            way["amenity"](area);
            rel["amenity"](area);
            node["tourism"](area);
            way["tourism"](area);
            rel["tourism"](area);
          );
          out center;

Any suggestions would be great


Solution

  • "name"="New York City" is wrong. The name in OSM is "City of New York", see https://www.openstreetmap.org/relation/175905. alt_name="New York City" could have worked.

    If you want to query for cities then adding place=city seems appropriate.

    I suggest some reading about OSM tags. https://wiki.openstreetmap.org/ is a good place to start.

    Another approach is to use a geocoder (for example Nominatim). Overpass API is not really meant for querying features by name.