Query Overpass API for roads in a specific country
Asked Answered
H

2

5

I'm trying to construct a query of all 'highway=' ways in a specific area in overpass. I've been defaulting to using the {{bbox}} - but I really would prefer to do it by country.

I've tried using 'nominatimArea:' instead of {{bbox}} but I get a parse error ' line 8: parse error: ')' expected - '(' found. ' on the below:

/*
This shows the roads in nepal.
*/

[out:json];

(
  way ["highway"~"motorway|trunk|primary|motorway_link|trunk_link|primary_link|unclassified|tertiary|secondary|track|path"]({{nominatimArea:Nepal}});
);

out meta;
>;
out skel qt;

ALSO ... if I try this...I only (weirdly) get one area - no ways (maybe the relations are a mess?)

/*
This shows the roads in nepal.
*/

[out:json];

(area[name="Nepal"];
  way(area) ["highway"~"motorway|trunk|primary|motorway_link|trunk_link|primary_link|unclassified|tertiary|secondary|track|path|residential|service"];
);

out meta;
>;
out skel qt;

Returns this one item (and it is an area NOT a way)

Note: I know this is a large query - but I really just need the url to the raw JSON (like this) - not the actual overpass map result.

Hartshorn answered 13/5, 2015 at 19:11 Comment(0)
H
9

Got it.

/*
This shows the roads in nepal.
*/

[out:json];

area[name="नेपाल"];
 (way["highway"~"motorway|trunk|primary|motorway_link|trunk_link|primary_link|unclassified|tertiary|secondary|track|path|residential|service|secondary_link|tertiary_link"](area);
);

out meta;
>;
out skel qt;
Hartshorn answered 14/5, 2015 at 0:14 Comment(0)
B
0

A modification to user14696's answer as usually difficult to use local names. It would be more convenient to use your own language or English which most countries already had it set.

Use specific language tag and administrative level filter

[out:json];
    
area["name:en"="Nepal"][admin_level=2];
//area["name:en"="Gandaki Province"][admin_level=4];
//area["name"="Waling"][admin_level=7];
(
  way["highway"~
    "motorway|trunk|primary|
      |motorway_link|trunk_link|primary_link|
      |unclassified|tertiary|secondary|
      |track|path|residential|service|
      |secondary_link|tertiary_link|
      "]
    (area);
);
    
out meta;
>;
out skel qt;

Notes

  • Some places have missing tags and some may have specific way of naming like dual language and triple language. So specific language name:xxx may more helpful then local name tag.

  • In many places, same town name is used multiple administrative levels, so it is good to filter by admin_level too.

  • Some queries are very heavy, may be fast to try on small area at the start.

  • Keep OpenStreetMap page open, and look for tag which may help or may be contribute missing tags. For example: Waling has only name tag and it is in English. while many other tags with Nepal (anyway, it is a country level)

Becky answered 22/9, 2023 at 6:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.