Skip to content

Instantly share code, notes, and snippets.

@JamesChevalier
Last active March 20, 2024 13:33
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamesChevalier/b861388d35476cee4fcc3626a60af60f to your computer and use it in GitHub Desktop.
Save JamesChevalier/b861388d35476cee4fcc3626a60af60f to your computer and use it in GitHub Desktop.
Overpass API query to retrieve all streets in a city

An area ID in Overpass is the OSM relation ID + 3600000000

This information is kind of buried in the Overpass API wiki page documenting the available filters: https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL#By_area_.28area.29

The OSM relation ID can be seen in two places:

  • Visit https://www.openstreetmap.org and search for the city
  • Click on its entry and you will be taken to a https://www.openstreetmap.org/relation/SOME_NUMBER_HERE page
  • The relation ID is in the URL as "SOME_NUMBER_HERE" in the bullet point above
  • The relation ID will also be in parentheses next to the city name in the left column

This query will return all of the nodes for any street that has any node within the area boundary:

[timeout:900][out:json];
area(3600000000 + OSM_RELATION_ID);
(
way(area)
['name']
['highway']
['highway' !~ 'path']
['highway' !~ 'steps']
['highway' !~ 'motorway']
['highway' !~ 'motorway_link']
['highway' !~ 'raceway']
['highway' !~ 'bridleway']
['highway' !~ 'proposed']
['highway' !~ 'construction']
['highway' !~ 'elevator']
['highway' !~ 'bus_guideway']
['highway' !~ 'footway']
['highway' !~ 'cycleway']
['foot' !~ 'no']
['access' !~ 'private']
['access' !~ 'no'];
);
(._;>;);
out;

This query will return only the nodes within the area for any street that has any node within the area boundary:

[timeout:900][out:json];
area(3600251075)->.a;
(
  way(area.a)
  ['name']
  ['highway']
  ['highway' !~ 'path']
  ['highway' !~ 'steps']
  ['highway' !~ 'motorway']
  ['highway' !~ 'motorway_link']
  ['highway' !~ 'raceway']
  ['highway' !~ 'bridleway']
  ['highway' !~ 'proposed']
  ['highway' !~ 'construction']
  ['highway' !~ 'elevator']
  ['highway' !~ 'bus_guideway']
  ['highway' !~ 'footway']
  ['highway' !~ 'cycleway']
  ['foot' !~ 'no']
  ['access' !~ 'private']
  ['access' !~ 'no'];
  node(w)(area.a);
);
out;
@stormstricker
Copy link

Please, write a wrapper that does it ; (

@4gus71n
Copy link

4gus71n commented Apr 4, 2020

@stormstricker I'm working on something related to this. I've created a small wrapper, in the case that this is useful for anyone else.

https://gist.github.com/4gus71n/26589a508d8deca333bb05928fd4beb0

@PrzemekKlocek
Copy link

@stormstricker I'm working on something related to this. I've created a small wrapper, in the case that this is useful for anyone else.

https://gist.github.com/4gus71n/26589a508d8deca333bb05928fd4beb0

Awesome script! If I could ask - could You provided a hint how to remake this into country->cities from cities->streets?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment