query-f14d1fc5f88063f00c5e8936613beb0e

rq turtle/ttl

Mfchris84

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX geof: <http://www.opengis.net/def/geosparql/function/>

SELECT ?bookcase ?bookcaseLabel ?location1 ?library ?libraryLabel ?location2 ?distance
WHERE {
 {
SELECT ?bookcase ?location1 ?library ?location2 ?distance WHERE {
 {
SELECT ?bookcase ?location1 (MIN(?distance) AS ?minDistance) WHERE {
?bookcase wdt:P31 wd:Q294297;
wdt:P625 ?location1;
wdt:P17 wd:Q40.
?library wdt:P31 wd:Q28564;
wdt:P625 ?location2;
wdt:P17 wd:Q40.
BIND(geof:distance(?location1, ?location2) AS ?distance)
}
GROUP BY ?bookcase ?location1
}
?library wdt:P31 wd:Q28564;
wdt:P625 ?location2;
wdt:P17 wd:Q40.
BIND(geof:distance(?location1, ?location2) AS ?distance)
FILTER(?distance = ?minDistance)
}
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v3("?bookcase"):::projected v7("?distance"):::projected v5("?library"):::projected v4("?location1"):::projected v6("?location2"):::projected v7("?minDistance") c8(["bd:serviceParam"]):::iri c6(["wd:Q28564"]):::iri c5(["wd:Q40"]):::iri c10(["#91;AUTO_LANGUAGE#93;,en"]):::literal c2(["wd:Q294297"]):::iri f0[["?distance = ?minDistance"]] f0 --> v7 f0 --> v7 v3 --"wdt:P31"--> c2 v3 --"wdt:P625"--> v4 v3 --"wdt:P17"--> c5 v5 --"wdt:P31"--> c6 v5 --"wdt:P625"--> v6 v5 --"wdt:P17"--> c5 bind1[/"http://www.opengis.net/def/geosparql/function/distance(?location1,?location2)"/] v4 --o bind1 v6 --o bind1 bind1 --as--o v7 bind3[/"min(?distance)"/] v7 --o bind3 bind3 --as--o v7 v5 --"wdt:P31"--> c6 v5 --"wdt:P625"--> v6 v5 --"wdt:P17"--> c5 bind4[/"http://www.opengis.net/def/geosparql/function/distance(?location1,?location2)"/] v4 --o bind4 v6 --o bind4 bind4 --as--o v7 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c8 --"wikibase:language"--> c10 end