ES:Ejemplos de Overpass QL frente a SPARQL
Si comprendes el artículo original en inglés, por favor, ayuda a completar esta traducción al español. Lee las instrucciones sobre cómo traducir este wiki.
dcapillae está trabajando ahora en esta traducción.
This page compares basic querying tasks between 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.
Nodos con una etiqueta determinada
Muestra un mapa interactivo de los nodos etiquetados como office=education.
SPARQL | Overpass QL | Overpass turbo query wizard |
---|---|---|
#defaultView:Map
SELECT * WHERE {
?osmId osmm:type "n" ;
osmt:office "education" ;
osmm:loc ?loc .
}
|
node["office"="education"]({{bbox}});
out body;
>;
out skel qt;
|
office=education and type:node
|
Características con una etiqueta dada
Muestra un mapa interactivo de nodos, vías y relaciones etiquetados como office=education.
SPARQL | Overpass QL | Overpass turbo query wizard |
---|---|---|
#defaultView:Map
SELECT * WHERE {
?osmId osmt:office "education" ;
osmm:loc ?loc .
}
|
[out:json][timeout:25];
// gather results
(
nwr["office"="education"]({{bbox}});
);
// print results
out body;
>;
out skel qt;
|
office=education
|
Features with one tag but not another
Displays an interactive map of nodes, ways, and relations that are tagged office=education but not building=*.
SPARQL | Overpass QL | Overpass turbo query wizard |
---|---|---|
#defaultView:Map
SELECT * WHERE {
?osmId osmt:office "education" ;
osmm:loc ?loc .
FILTER NOT EXISTS {
?osmId osmt:building [].
}
}
|
[out:json][timeout:25];
// gather results
(
nwr["office"="education"][!"building"]({{bbox}});
);
// print results
out body;
>;
out skel qt;
|
office=education and building is null
|
Features within a specific bounding box
Displays an interactive map of nodes, ways, and relations that are tagged leisure=pitch but not sport=* and that are located within a specific bounding box encompassing the Dallas area. You can use a tool like bboxfinder or geojson.io to calculate a bounding box.
SPARQL | Overpass QL | Overpass turbo query wizard |
---|---|---|
#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 [].
}
}
|
nwr["leisure"="pitch"][!"sport"](32.5,-97.0,33.0,-96.6);
out body;
>;
out skel qt;
|
leisure=pitch and sport is null (then click the picture frame icon to choose the bounding box)
|
Features within a radius of a specific coordinate
Displays an interactive map of nodes, ways, and relations tagged leisure=pitch but not sport=* that fall within 300 kilometres (190 mi) of a specific coordinate, approximating Suriname.
SPARQL | Overpass QL | Overpass turbo query wizard |
---|---|---|
#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 [] .
}
}
|
nwr(around:300000,4.00,-56.00)["leisure"="pitch"][!"sport"];
out body;
>;
out skel qt;
|
leisure=pitch and sport is null around "4.00,-56.00"
|
Matching part of a tag value
Displays an interactive map of features tagged place=village whose name=* contains the substring or regular expression "View". SPARQL has functions for matching substrings or regular expressions, while OverpassQL only has a filter for regular expressions.
SPARQL | Overpass QL | Overpass turbo query wizard |
---|---|---|
#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")
}
|
[out:json][timeout:250];
(
nwr["place"="village"]["name"~"View"];
);
out body;
>;
out skel qt;
|
place=village and name~View
|
Features with either one tag or another tag
Displays an interactive map of nodes, ways, and relations tagged office=education or sport=pilates or both.
SPARQL | Overpass QL | Overpass turbo query wizard |
---|---|---|
#defaultView:Map
SELECT * WHERE {
{
?osm osmt:office "education" ;
} UNION {
?osm osmt:sport "pilates" .
}
?osm osmm:loc ?loc .
}
|
(
nwr["office"="education"]({{bbox}});
nwr["sport"="pilates"]({{bbox}});
);
out body;
>;
out skel qt;
|
office=education or sport=pilates
|
Filter features by last-edited timestamp
Displays an interactive map of nodes, ways, and relations tagged leisure=* that were last edited on 10 August 2020 (UTC).
SPARQL | Overpass QL | Overpass turbo query 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)
}
|
(
nwr["leisure"](newer:"2020-08-10T00:00:00Z")({{bbox}});
- nwr["leisure"](newer:"2020-08-11T00:00:00Z")({{bbox}});
);
out body;
>;
out skel qt;
|
N/A |