2

I am trying to prepare a Overpass QL such a way that it iterate through a list of City Names and find sum of lengths of all the road centerline features which are falling inside the city administrative boundary.

The idea is not to download to entire data rather to get only required total road length per city wise.

  • New York City, New York, USA
  • Toronto, Ontario, Canada
  • Jersey city, New Jersey, USA
  • <City_Name>, <STATE/PROVINCE>,

Above is the example input and below is sample QL with BBOX but need to automate either with overpy Python AOI or writing single overpass QL for entire list of cities.

[out:json][timeout:25][bbox:{{bbox}}];
(way["highway"="primary"];
 way["highway"="secondary"];
 way["highway"="tertiary"];
 way["highway"="unclassified"];
 way["highway"="residential"];);
(._;>;);
out;

Can someone give me pointers?

3
  • How many citites do you want to process? May it would be better to download a PBF extract for US instead. – mmd Aug 25 '20 at 9:09
  • I might need to iterate through thousands of cities, if nothing works out well, might need to download entire USA data which is huge in size, IMO. – Prem Aug 25 '20 at 16:01
  • Yes, that sounds like you want to download a US extract and use osm2pgsql and a Postgis database for this kind of analysis. – mmd Aug 25 '20 at 18:40
0

Looking at the overpass example had some useful examples:

/*
This has been generated by the overpass-turbo wizard.
The original search was:
“highway=* and type:way in "West Midlands"”
*/
[out:json][timeout:500];
// fetch area “West Midlands” to search in
{{geocodeArea:West Midlands}}->.searchArea;
// gather results
(
 way["highway"="primary"];
 way["highway"="secondary"];
 way["highway"="tertiary"];
 way["highway"="unclassified"];
 way["highway"="residential"];
);
make stat number=count(ways),length=sum(length());
out;

Just need to tweak the geocoded area to be whatever city or bounding box you want. The query is quite resource intensive so you may hit a quota limit unless you run your own overpass server.

2
  • OP asked for a solution to iterate over a list of cities really, so you would probably need to add a foreach statement as well. Still, I don't think this makes sense for a larger number of cities. – mmd Aug 25 '20 at 14:38
  • Hi Alex, thanks for the sample code, however, as I have to do the same for almost thousands of cities which is not possible to execute manually. so, I have tried automating it through python but given geocodeArea tag is a geocoding service specific to overpass turbo. but when we try to execute the above sample via python, it fails because it cannot identify geocodeArea tag. I need to explicitly mention <CITY><STATE><COUNTRY> to ovoid miscalculation if there might be several cities with same name. Trying couple of opensource geocoding services to handle city BBOX, will post here. – Prem Aug 25 '20 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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