query-f18d5c35224f272c3d3b082820ff89e3
Mfchris84
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#>
#defaultView:Map{"hide": ["?location", "?layer"]}
SELECT ?item ?itemLabel ?location ?layer
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)
}
}
VALUES ?switch { true false }
BIND(IF(?switch, "bookcase"@en, "library"@en) AS ?layer)
BIND(IF(?switch, ?bookcase, ?library) AS ?item)
BIND(IF(?switch, ?location1, ?location2) AS ?location)
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,de". }
}
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v3("?bookcase")
  v7("?distance")
  v9("?item"):::projected 
  v8("?layer"):::projected 
  v5("?library")
  v10("?location"):::projected 
  v4("?location1")
  v6("?location2")
  v7("?minDistance")
  v7("?switch")
  c8(["bd:serviceParam"]):::iri 
  c6(["wd:Q28564"]):::iri 
  c5(["wd:Q40"]):::iri 
  c10(["#91;AUTO_LANGUAGE#93;,en,de"]):::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/function/geosparql/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/function/geosparql/distance(?location1,?location2)"/]
  v4 --o bind4
  v6 --o bind4
  bind4 --as--o v7
  bind5[/VALUES ?switch/]
  bind5-->v7
  bind50(["true^^xsd:boolean"])
  bind50 --> bind5
  bind51(["false^^xsd:boolean"])
  bind51 --> bind5
  bind6[/"if(?switch,sbookcase^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>',slibrary^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>')"/]
  v7 --o bind6
  bind6 --as--o v8
  bind7[/"if(?switch,?bookcase,?library)"/]
  v7 --o bind7
  v3 --o bind7
  v5 --o bind7
  bind7 --as--o v9
  bind8[/"if(?switch,?location1,?location2)"/]
  v7 --o bind8
  v4 --o bind8
  v6 --o bind8
  bind8 --as--o v10
  subgraph s1["http://wikiba.se/ontology#label"]
    style s1 stroke-width:4px;
    c8 --"wikibase:language"-->  c10
  end