query-ec3edfb0f975accf835b6db4938fdffa
Query #13: All articles with pictures within X [kilometers] of a locationExample of searching for pictures near a particular location
Use at
- https://query.wikidata.org/sparql
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX geof: <http://www.opengis.net/def/function/geosparql/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?place ?placeLabel ?pic ?location ?instanceLabel
WHERE
{
wd:Q462042 wdt:P625 ?loc . # <-- Change the Q-Code to a geographic entiry
SERVICE wikibase:around {
?place wdt:P625 ?location .
bd:serviceParam wikibase:center ?loc .
bd:serviceParam wikibase:radius "100" . # <-- Specify a distance
}
OPTIONAL { ?place wdt:P31 ?instance }
#OPTIONAL {?place wdt:P18 ?pic} # toggle comment character to see all links in radius
?place wdt:P18 ?pic
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
BIND(geof:distance(?loc, ?location) as ?dist)
} ORDER BY ?dist
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v7("?dist")
v5("?instance")
v2("?loc")
v4("?location"):::projected
v6("?pic"):::projected
v3("?place"):::projected
c7(["100"]):::literal
c4(["bd:serviceParam"]):::iri
c1(["wd:Q462042"]):::iri
c12(["en"]):::literal
c1 --"wdt:P625"--> v2
subgraph s1["http://wikiba.se/ontology#around"]
style s1 stroke-width:4px;
v3 --"wdt:P625"--> v4
c4 --"wikibase:center"--> v2
c4 --"wikibase:radius"--> c7
end
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v3 -."wdt:P31".-> v5
end
v3 --"wdt:P18"--> v6
subgraph s2["http://wikiba.se/ontology#label"]
style s2 stroke-width:4px;
c4 --"wikibase:language"--> c12
end
bind0[/"http://www.opengis.net/def/function/geosparql/distance(?loc,?location)"/]
v2 --o bind0
v4 --o bind0
bind0 --as--o v7