TransWikia.com

Overpass API: Loop through cities and find total length of road centerline per city

Geographic Information Systems Asked by Prem on June 14, 2021

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?

One Answer

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.

Answered by Alex Dawn on June 14, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP