You are in: Rob's OSM Stuff » Notes » Overpass Queries

Useful Overpass API / Turbo Queries

The following are example queries for the OSM Overpass API / Overpass Turbo that I find useful. Feel free to use and adapt them for your own needs.

BBox query using Postpass


{{data:sql,server=https://postpass.geofabrik.de/api/0.2/}}
SELECT osm_id, osm_type, tags, geom
FROM postpass_pointlinepolygon
WHERE tags->>'amenity'='toilets'
  AND NOT(tags ? 'access')
  AND geom && {{bbox}}

Global query using Postpass


{{data:sql,server=https://postpass.geofabrik.de/api/}}
SELECT osm_id, osm_type, tags, geom
FROM postpass_pointlinepolygon
WHERE tags @> '{"operator:wikidata":"Q73072837"}'

Note the use of "tags @>" to ensure that the tags index is used. Otherwise the query would be very slow to run.

Apply Query just within the UK, Channel Islands and Isle of Man:


[out:xml][timeout:240];
(area["ISO3166-1"="GB"][admin_level=2];
 area["ISO3166-1"="IM"][admin_level=2];
 area["ISO3166-1"="GG"][admin_level=2];
 area["ISO3166-1"="JE"][admin_level=2];)->.a;
(nwr["name"="foobar"](area.a););
(._;>;); out meta;

Query for objects with a certain name without a matching brand:wikidata tag in the UK, Channel Islands and Isle of Man:


[out:xml][timeout:240];
(area["ISO3166-1"="GB"][admin_level=2];
 area["ISO3166-1"="IM"][admin_level=2];
 area["ISO3166-1"="GG"][admin_level=2];
 area["ISO3166-1"="JE"][admin_level=2];)->.a;
(nwr["name"="Zizzi"]["brand:wikidata"!="Q8072944"](area.a););
(._;>;); out meta;

Return objects where two tag values are the same


[out:xml][timeout:240];
(area["ISO3166-1"="GB"][admin_level=2];
 area["ISO3166-1"="IM"][admin_level=2];
 area["ISO3166-1"="GG"][admin_level=2];
 area["ISO3166-1"="JE"][admin_level=2];)->.a;
(nwr["not:brand:wikidata"]["brand:wikidata"](if: t["not:brand:wikidata"] == t["brand:wikidata"])(area.a););
(._;>;); out meta;

Inconsistent Lifecycle prefixes


[out:xml][timeout:240];
(area["ISO3166-1"="GB"][admin_level=2];
 area["ISO3166-1"="IM"][admin_level=2];
 area["ISO3166-1"="GG"][admin_level=2];
 area["ISO3166-1"="JE"][admin_level=2];)->.a;
(nwr["disused:shop"]["shop"](area.a);
 nwr["disused:shop"]["amenity"](area.a);
 nwr["disused:amenity"]["shop"](area.a);
 nwr["disused:amenity"]["amenity"](area.a););
(._;>;); out meta;

Find objects matching one query, within areas matching another


[out:xml][timeout:60][bbox:{{bbox}}];
wr[highway=services];
map_to_area -> .a;
nwr(area.a)["brand:wikidata"="Q1548712"];
 out meta; > ; (._;>;); out meta;

Local search for maxweight=* tags

In the UK, weight restrictions are almost always based on MGW, which should be tagged with maxweightrating=*. Moreover, the most common sign, with the weight inside a truck, means the restriction only applied to goods vehicles, so maxweightrating:hgv=* should be used in this case. The Overpass turbo code below shows likely incorrect restrictions as black lines, and common correct restrictions as coloured lines (different shades of red/orange for HGV restrictions, and different shades of blue for all vehicle restrictions.


[out:xml][timeout:240];
(nwr["maxweightrating:hgv"]({{bbox}});
 nwr["maxweightrating"]({{bbox}});
 nwr["maxweight"]({{bbox}});
 nwr["maxweight:hgv"]({{bbox}});
 nwr["maxweight:conditional"]({{bbox}});
 nwr["maxweight:hgv:conditional"]({{bbox}});
);
(._;>;);
out meta;

{{style:
*
{render:native;}
*[maxweightrating:hgv], *[maxweightrating]
{ color: #808080; }
*[maxweightrating:hgv=18], *[maxweightrating:hgv=18 T], *[maxweightrating:hgv=18 t]
{ color: #800000; }
*[maxweightrating:hgv=7.5], *[maxweightrating:hgv=7.5 T], *[maxweightrating:hgv=7.5 t]
{ color: #FF4000; }
*[maxweightrating:hgv=3.5], *[maxweightrating:hgv=3.5 T], *[maxweightrating:hgv=3.5 t]
{ color: #A0A000; }
*[maxweightrating=18], *[maxweightrating=18 T], *[maxweightrating=18 t]
{ color: #000080; }
*[maxweightrating=7.5], *[maxweightrating=7.5 T], *[maxweightrating=7.5 t]
{ color: #0040FF; }
*[maxweightrating=3.5], *[maxweightrating=3.5 T], *[maxweightrating=3.5 t]
{ color: #00A0A0; }
*[maxweight:hgv], *[maxweight], *[maxweight:hgv:conditional], *[maxweight:conditional]
{ color: #000000; opacity:1; width:3}
node
{opacity:0; fill-opacity:0}
}}

Non-Credit-Union Banks that lack a brand:wikidata tag in the UK, IoM and Channel Islands


[out:xml][timeout:240];
(area["ISO3166-1"="GB"][admin_level=2];
 area["ISO3166-1"="IM"][admin_level=2];
 area["ISO3166-1"="GG"][admin_level=2];
 area["ISO3166-1"="JE"][admin_level=2];)->.a;
(nwr[amenity=bank][!"brand:wikidata"][bank!=credit_union](area.a););
(._;>;); out meta;

Query for objects with wikidata=* and addr:street=*, but no building=* tag

Designed to catch erroneous matching of a wikidata item for a building via an address on a POI, with some common false positives removed.


[out:xml][timeout:60];
nwr["wikidata"]["addr:street"][!building]
   [amenity!=recycling]
   [amenity!=university]
   [amenity!=college]
   [amenity!=library]
   [amenity!=school]
   [tourism!=museum]
   [landuse!=military]
   [railway!=station]  
({{bbox}});
(._;>;);
out meta;

social_facility=* without amenity=social_facility


[out:xml][timeout:240];
(area["ISO3166-1"="GB"][admin_level=2];
 area["ISO3166-1"="IM"][admin_level=2];
 area["ISO3166-1"="GG"][admin_level=2];
 area["ISO3166-1"="JE"][admin_level=2];)->.a;
(nwr["social_facility"]["amenity"!="social_facility"](area.a););
(._;>;); out meta;

amenity=social_facility without social_facility=*


[out:xml][timeout:240];
(area["ISO3166-1"="GB"][admin_level=2];
 area["ISO3166-1"="IM"][admin_level=2];
 area["ISO3166-1"="GG"][admin_level=2];
 area["ISO3166-1"="JE"][admin_level=2];)->.a;
(nwr["amenity"="social_facility"][!"social_facility"](area.a););
(._;>;); out meta;

Query for brand:wikidata tags on objects without a primary tag


[out:xml][timeout:240];
(area["ISO3166-1"="GB"][admin_level=2];
 area["ISO3166-1"="IM"][admin_level=2];
 area["ISO3166-1"="GG"][admin_level=2];
 area["ISO3166-1"="JE"][admin_level=2];)->.a;
(nwr["brand:wikidata"]
    [!"shop"][!"amenity"][!"tourism"]
    [!"leisure"][!"healthcare"][!"office"]
    [!"craft"][!"emergency"][!"route"]
    [!"club"][!"power"][!"advertising"]
    [!"man_made"][!"industrial"]
  (area.a););
(._;>;);
out meta;

tourism=information without an information=* tag


[out:xml][timeout:240];
(area["ISO3166-1"="GB"][admin_level=2];
 area["ISO3166-1"="IM"][admin_level=2];
 area["ISO3166-1"="GG"][admin_level=2];
 area["ISO3166-1"="JE"][admin_level=2];)->.a;
(nwr["tourism"="information"][!"information"](area.a););
(._;>;);
out meta;

Websites still using http


[out:xml][timeout:25];
nwr["website"~"http:"]({{bbox}});
(._;>;);
out meta;

UK road crossing nodes without a main categorisation tag


[out:xml][timeout:240];
(node["highway"="crossing"]
["crossing_ref"!="zebra"]
["crossing_ref"!="pelican"]
["crossing_ref"!="puffin"]
["crossing_ref"!="toucan"]
["crossing_ref"!="pegasus"]
["crossing_ref"!="parallel"]
["crossing_ref"!="informal_zebra"]
["crossing"!="raised_table"]
["crossing"!="unmarked"]
({{bbox}}););
out meta;

Possible additions: crossing=informal (for desire line crossings without drop-curbs; crossing:markings=no as an alternative to crossing=unmarked.

Nodes at the intersection of roads and paths without a crossing tag


[out:xml][timeout:240];
( 
  way["highway"="footway"]({{bbox}});
  way["highway"="cycleway"]({{bbox}});
  way["highway"="path"]({{bbox}});
  way["highway"="bridleway"]({{bbox}});
);
node(way_link:2-)->.p;
(
  way["highway"="trunk"]({{bbox}});
  way["highway"="primary"]({{bbox}});
  way["highway"="secondary"]({{bbox}});
  way["highway"="tertiary"]({{bbox}});
  way["highway"="trunk_link"]({{bbox}});
  way["highway"="primary_link"]({{bbox}});
  way["highway"="secondary_link"]({{bbox}});
  way["highway"="tertiary_link"]({{bbox}});
  way["highway"="unclassified"]({{bbox}});
  way["highway"="residential"]({{bbox}});
);
node(way_link:2-)->.r;
node.p.r[highway!=crossing][crossing!=informal];
out meta;

UK Objects with both website=* and contact:website=*


[out:xml][timeout:240];
(area["ISO3166-1"="GB"][admin_level=2];
 area["ISO3166-1"="IM"][admin_level=2];
 area["ISO3166-1"="GG"][admin_level=2];
 area["ISO3166-1"="JE"][admin_level=2];)->.a;
(nwr["contact:website"]["website"](area.a););
(._;>;);
out meta;