2

I want to get all streets in NYC using http://overpass-turbo.eu/. I tried this:

[out:json]; area[name = "New York"]; (node(area)[highway=street]; ); out;

However it returns

{
  "version": 0.6,
  "generator": "Overpass API 0.7.55.1009 5e627b63",
  "osm3s": {
    "timestamp_osm_base": "2019-11-13T19:26:03Z",
    "timestamp_areas_base": "2019-11-13T18:05:02Z",
    "copyright": "The data included in this document is from www.openstreetmap.org. The data is made available under ODbL."
  },
  "elements": [



  ]
}

No elements. However this query:

[out:json]; area[name = "New York"]; ( node(area)[amenity=cinema]; node(area)[highway=street]; ); out;

for getting streets and cinemas, works:

{
  "version": 0.6,
  "generator": "Overpass API 0.7.55.1009 5e627b63",
  "osm3s": {
    "timestamp_osm_base": "2019-11-13T19:29:02Z",
    "timestamp_areas_base": "2019-11-13T18:05:02Z",
    "copyright": "The data included in this document is from www.openstreetmap.org. The data is made available under ODbL."
  },
  "elements": [

{
  "type": "node",
  "id": 344994897,
  "lat": 41.7680892,
  "lon": -73.9291000,
  "tags": {
    "amenity": "cinema",
    "created_by": "Potlatch 0.10f",
    "name": "Roosevelt Theater"
  }
},
{
  "type": "node",
  "id": 344996199,
  "lat": 41.7727941,
  "lon": -73.9292159,
  "tags": {
    "amenity": "cinema",
    "created_by": "Potlatch 0.10f",
    "name": "Hyde Park Drive-In"
  }
},
{
  "type": "node",
  "id": 368043485,
  "lat": 40.7259416,
  "lon": -73.9973321,
  "tags": {
    "addr:state": "NY",
    "amenity": "cinema",
    "ele": "10",
    "gnis:county_name": "New York",
    "gnis:feature_id": "2082840",
    "gnis:import_uuid": "57871b70-0100-4405-bb30-88b2e001a944",
    "gnis:reviewed": "no",
    "name": "Angelika Film Center",
    "source": "USGS Geonames",
    "wikidata": "Q45104731"
  }
},
...

How should I modify the initial query to get the streets?

EDIT:

I tried

[out:json];
area[name = "New Hampshire"]->.a;          // Redirect result to ".a"
out body qt;
(
  way
    (area.a)                    // Use result from ".a"
    ["highway"="living_street"];
);
out body qt;
>;
out skel qt;

but it didn't select all of the streets, just several. And how should I specify that I mean a state by New Hampshire? I need all streets with postcodes (zip).

this doesn't display any streets at all:

[out:json];
area[name = "Acworth"]->.a;          // Redirect result to ".a"
out body qt;
(
  way
    (area.a)                    // Use result from ".a"
    ["highway"="living_street"];
);
out body qt;
>;
out skel qt;

Although it should at least display these: https://geographic.org/streetview/usa/nh/sullivan/acworth.html

2

2 Answers 2

3

You can use a regular expression to combine several highway=* queries into a single one.

[out:json];
area[name = "New York"];
(way(area)["highway"~"^(motorway|trunk|primary)$"];>;);
out;

Note: this query returns more than 40 MB worth of data.

NB: Be sure to review https://help.openstreetmap.org/questions/20531/overpass-ql-nodes-and-ways-in-area when using multiple query statements for the same area.

1
  • 1
    I've removed my incorrect post in favor of @mmd's.
    – derivative
    Commented Nov 19, 2019 at 13:44
0

This Python script will query the Overpass API to get all cities in a US state. Since the API returns duplicates, the script removes them. Finally, the streets are sorted alphabetically and printed out.

import requests

def query_overpass_api(query):
    # Overpass API endpoint.
    overpass_url = "http://overpass-api.de/api/interpreter"

    params = {
        'data': query,
        'format': 'json'
    }

    response = requests.get(overpass_url, params=params)

    # If successful.
    if response.status_code == 200:
        return response.json()
    else:
        print(f"Error: {response.status_code}")
        return None

def get_streets_in_city(city, state):
    overpass_query = """
        [out:json];

        area["ISO3166-1"="US"]->.us;
        area["admin_level"="4"]["name"="{state}"]->.state;
        area["admin_level"="8"]["name"="{city}"]->.city;
        way(area.us)(area.state)(area.city)[highway][name];
        out tags;
    """.format(city=city, state=state)

    result = query_overpass_api(overpass_query)

    if not result:
        print("Error querying Overpass API.")
        return None

    streets = {}

    for element in result["elements"]:
        highway = element["tags"]["highway"]
        name = element["tags"]["name"]
        streets[name] = highway

    streets = dict(sorted(streets.items()))

    return streets

if __name__ == "__main__":
    # Example Overpass query to get all streets in Concord, NH.
    streets = get_streets_in_city("Concord", "New Hampshire")

    if streets:
        for street_name, street_type in streets.items():
            print(street_name + " - " + street_type)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.