Overpass query example

Motorway network of a country

Get every motorway segment of a country with its geometry. Example: Switzerland.

Roads are ways tagged highway=…. Long roads are split into many ways, so the motorways of a country are thousands of segments.

The query

[out:json][timeout:60];
area["ISO3166-1"="CH"][admin_level=2]->.ch;
way["highway"="motorway"](area.ch);
out geom;

Run it

Running the query…

Live result from overpass.ch, cached for up to 12 hours. Map data © OpenStreetMap contributors (ODbL).

How it works

  1. way["highway"="motorway"] returns the carriageways; ramps are motorway_link.
  2. out geom; adds coordinates to every way. Without it you get only node IDs.

Variations

  • Add expressways: ["highway"~"^(motorway|trunk)$"].
  • To get whole roads instead of segments, query the route relations: rel["route"="road"]["ref"="A1"].

Run it from your code

curl https://api.overpass.ch/v1/YOUR_API_KEY/interpreter \
  --data-urlencode 'data@query.overpassql'

Save the query as query.overpassql. It works the same in Overpass Turbo, QGIS and JOSM.

More examples

All examples →