SPARQL vs Overpass QL examples
This page compares basic querying tasks between QLever and Sophox's SPARQL language and the Overpass API's Overpass QL.
At a high level, Sophox is best suited for querying globally, while the Overpass API is best suited for querying locally or regionally. It is very easy to run into a timeout or out-of-memory error when performing a regional query using Sophox or performing a global query using the Overpass API. The Overpass QL examples below all specify a specific bounding box or the currently viewed bounding box; it is possible but less common to omit the ({{bbox}}) filter to perform a global query. Likewise, you can use the wikibase:box service to limit a SPARQL query to a bounding box.
Nodes with a given tagDisplays an interactive map of nodes tagged | |||
|---|---|---|---|
| QLever SPARQL | Sophox SPARQL | Overpass QL | Overpass turbo wizard |
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX osmkey: <https://www.openstreetmap.org/wiki/Key:>
PREFIX osm: <https://www.openstreetmap.org/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT * WHERE {
?osmId rdf:type osm:node;
osmkey:office "education" ;
geo:hasGeometry/geo:asWKT ?loc .
}
|
#defaultView:Map
SELECT * WHERE {
?osmId osmm:type "n" ;
osmt:office "education" ;
osmm:loc ?loc .
}
|
office=education and type:node
| |
Nodes and ways with a given keyDisplays an interactive map of nodes and ways tagged with key | |||
| QLever SPARQL | Sophox SPARQL | Overpass QL | Overpass turbo wizard |
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX osmkey: <https://www.openstreetmap.org/wiki/Key:>
PREFIX osm: <https://www.openstreetmap.org/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT * WHERE {
VALUES ?types { osm:node osm:way }
?osmId rdf:type ?types;
osmkey:crane:type ?key;
geo:hasGeometry/geo:asWKT ?loc.
}
|
#defaultView:Map
SELECT * WHERE {
VALUES ?types { "n" "w" }
?osmId osmm:type ?types;
osmt:crane:type ?key;
osmm:loc ?loc.
}
|
crane:type=* and type:node or crane:type=* and type:way
| |
Features with a given tagDisplays an interactive map of nodes, ways, and relations that are tagged | |||
| QLever SPARQL | Sophox SPARQL | Overpass QL | Overpass turbo wizard |
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX osmkey: <https://www.openstreetmap.org/wiki/Key:>
SELECT * WHERE {
?osmId osmkey:office "education" ;
geo:hasGeometry/geo:asWKT ?loc .
}
|
#defaultView:Map
SELECT * WHERE {
?osmId osmt:office "education" ;
osmm:loc ?loc .
}
|
office=education
| |
Features with a couple of given tagsDisplays an interactive map of nodes, ways, and relations that are tagged | |||
| QLever SPARQL | Sophox SPARQL | Overpass QL | Overpass turbo wizard |
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX osmkey: <https://www.openstreetmap.org/wiki/Key:>
SELECT * WHERE {
?osmId osmkey:highway "primary" ;
osmkey:junction "roundabout" ;
osmkey:lanes "3" ;
geo:hasGeometry/geo:asWKT ?loc .
}
|
#defaultView:Map
SELECT * WHERE {
?osmId osmt:highway "primary" ;
osmt:junction "roundabout" ;
osmt:lanes "3" ;
osmm:loc ?loc .
}
|
highway=primary and junction=roundabout and lanes=3
| |
Features with one tag but not another keyDisplays an interactive map of nodes, ways, and relations that are tagged | |||
| QLever SPARQL | Sophox SPARQL | Overpass QL | Overpass turbo wizard |
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX osmkey: <https://www.openstreetmap.org/wiki/Key:>
SELECT * WHERE {
?osmId osmkey:office "education" ;
geo:hasGeometry/geo:asWKT ?loc .
MINUS { ?osmId osmkey:building [] . }
}
|
#defaultView:Map
SELECT * WHERE {
?osmId osmt:office "education" ;
osmm:loc ?loc .
FILTER NOT EXISTS {
?osmId osmt:building [].
}
}
|
office=education and building is null
| |
Features with one tag but not another tagDisplays an interactive map of nodes, ways, and relations that are tagged | |||
| QLever SPARQL | Sophox SPARQL | Overpass QL | Overpass turbo wizard |
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX osmkey: <https://www.openstreetmap.org/wiki/Key:>
SELECT * WHERE {
?osmId osmkey:office "education" ;
geo:hasGeometry/geo:asWKT ?loc .
MINUS { ?osmId osmkey:building "yes" . }
}
|
#defaultView:Map
SELECT * WHERE {
?osmId osmt:office "education" ;
osmm:loc ?loc .
FILTER NOT EXISTS {
?osmId osmt:building "yes".
}
}
|
office=education and building!=yes | |
Features with some tags but not another tagsDisplays an interactive map of nodes, ways, and relations that are tagged | |||
| QLever SPARQL | Sophox SPARQL | Overpass QL | Overpass turbo wizard |
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX osmkey: <https://www.openstreetmap.org/wiki/Key:>
SELECT * WHERE {
?osmId osmkey:lanes "1" ;
osmkey:highway "primary" ;
geo:hasGeometry/geo:asWKT ?loc .
MINUS { ?osmId osmkey:oneway "yes" . }
MINUS { ?osmId osmkey:junction "roundabout" . }
}
|
#defaultView:Map
SELECT * WHERE {
?osmId osmt:lanes "1" ;
osmt:highway "primary" ;
osmm:loc ?loc .
FILTER NOT EXISTS {
?osmId osmt:oneway "yes".
}
FILTER NOT EXISTS {
?osmId osmt:junction "roundabout".
}
}
|
lanes=1 and highway=primary and oneway!=yes and junction!=roundabout | |
Features within a specific bounding boxDisplays an interactive map of nodes, ways, and relations that are tagged | |||
| QLever SPARQL | Sophox SPARQL | Overpass QL | Overpass turbo wizard |
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX osmkey: <https://www.openstreetmap.org/wiki/Key:>
PREFIX geof: <http://www.opengis.net/def/function/geosparql/>
SELECT * WHERE {
?osmId osmkey:leisure "pitch" ;
geo:hasGeometry/geo:asWKT ?loc.
MINUS { ?osmId osmkey:sport [] . }
BIND(geof:latitude(?loc) AS ?lat)
BIND(geof:longitude(?loc) AS ?lon)
FILTER (?lon > -97.00 && ?lon < -96.60 && ?lat > 32.50 && ?lat < 33.00)
}
|
#defaultView:Map
SELECT * WHERE {
?osmId osmt:leisure "pitch".
# Filter bbox
SERVICE wikibase:box {
?osmId osmm:loc ?coordinates .
bd:serviceParam wikibase:cornerSouthWest 'Point(-97.00 32.50)'^^geo:wktLiteral.
bd:serviceParam wikibase:cornerNorthEast 'Point(-96.60 33.00)'^^geo:wktLiteral.
}
FILTER NOT EXISTS {
?osmId osmt:sport [].
}
}
|
leisure=pitch and sport is null (then click the picture frame icon to choose the bounding box)
| |
Features within a radius of a specific coordinateDisplays an interactive map of nodes, ways, and relations tagged | |||
| QLever SPARQL | Sophox SPARQL | Overpass QL | Overpass turbo wizard |
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX osmkey: <https://www.openstreetmap.org/wiki/Key:>
PREFIX geof: <http://www.opengis.net/def/function/geosparql/>
SELECT * WHERE {
?osmId osmkey:leisure "pitch" ;
geo:hasGeometry/geo:asWKT ?loc.
MINUS { ?osmId osmkey:sport [] . }
BIND ("Point(-56.00 4.00)"^^geo:wktLiteral AS ?center)
FILTER (geof:distance(?loc, ?center) <= 300)
}
|
#defaultView:Map
SELECT * WHERE {
?osmId osmt:leisure "pitch" .
SERVICE wikibase:around {
?osmId osmm:loc ?coordinates .
bd:serviceParam wikibase:center "Point(-56.00 4.00)"^^geo:wktLiteral .
bd:serviceParam wikibase:radius "300" .
bd:serviceParam wikibase:distance ?distance .
}
FILTER NOT EXISTS {
?osmId osmt:sport [] .
}
}
|
leisure=pitch and sport is null around "4.00,-56.00"
| |
Matching part of a tag valueDisplays an interactive map of features tagged | |||
| QLever SPARQL | Sophox SPARQL | Overpass QL | Overpass turbo wizard |
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX osmkey: <https://www.openstreetmap.org/wiki/Key:>
SELECT * WHERE {
?osmId osmkey:place "village" ;
osmkey:name ?name ;
geo:hasGeometry/geo:asWKT ?loc .
FILTER CONTAINS(?name, "View")
}
|
#defaultView:Map
SELECT * WHERE {
?osmId osmt:place "village" ;
osmt:name ?name ;
osmm:loc ?loc .
FILTER CONTAINS(?name, "View")
# Alternatively, match a regular expression
# for consistency with the OverpassQL query
# FILTER REGEX(?name, "View")
}
|
place=village and name~View
| |
Features with either one tag or another tagDisplays an interactive map of nodes, ways, and relations tagged | |||
| QLever SPARQL | Sophox SPARQL | Overpass QL | Overpass turbo wizard |
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX osmkey: <https://www.openstreetmap.org/wiki/Key:>
SELECT * WHERE {
{
?osm osmkey:office "education" .
} UNION {
?osm osmkey:sport "pilates" .
}
?osm geo:hasGeometry/geo:asWKT ?loc.
}
|
#defaultView:Map
SELECT * WHERE {
{
?osm osmt:office "education" ;
} UNION {
?osm osmt:sport "pilates" .
}
?osm osmm:loc ?loc .
}
|
office=education or sport=pilates
| |
Filter features by last-edited timestampDisplays an interactive map of nodes, ways, and relations tagged | |||
| QLever SPARQL | Sophox SPARQL | Overpass QL | Overpass turbo wizard |
#defaultView:Map
SELECT * WHERE {
?osmId osmt:leisure ?leisure ;
osmm:loc ?loc ;
osmm:timestamp ?ts .
# Filter by timestamp
FILTER ("2020-08-10T00:00:00Z"^^xsd:dateTime < ?ts &&
?ts < "2020-08-11T00:00:00Z"^^xsd:dateTime)
}
|
|||
Find relations which have a member with stated role name | |||
| QLever SPARQL | Sophox SPARQL | Overpass QL | Overpass turbo wizard |
#defaultView:Map
SELECT * WHERE {
?relation osmt:type "connectivity";
osmm:type "r";
osmm:has ?member;
?member "through".
}
|
|||
Features with a given tag touched from a specific userDisplays an interactive map of nodes, ways, and relations that are tagged with | |||
| QLever SPARQL | Sophox SPARQL | Overpass QL | Overpass turbo wizard |
#defaultView:Map
SELECT * WHERE {
?osmId osmt:office "education" ;
osmm:user "user_name";
osmm:loc ?loc .
}
|
office=education and user:user_name
| ||
Features with a given tag from a specific time periodDisplays an interactive map of nodes, ways, and relations that are tagged within a specific period of time and with the tag | |||
| QLever SPARQL | Sophox SPARQL | Overpass QL | Overpass turbo wizard |
#defaultView:Map
SELECT * WHERE {
?leisure osmt:office "education" ;
osmm:timestamp ?timestamp ;
osmm:loc ?loc .
# Filter by timestamp
FILTER("2012-01-01"^^xsd:dateTime < ?timestamp &&
?timestamp < "2013-01-01"^^xsd:dateTime)
}
|
|||
