query-e6fe75ea7b1f6f7efe152aec1fd578c9

rq turtle/ttl

Propertiescoordinate location (P625)instance of (P31)

Use at

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 DISTINCT ?hospital ?hospitalLabel ?dist
WHERE
{
  #use Potsdam main station as our location
  wd:Q647973 wdt:P625 ?centerLocation.

  #get all locations in within a 3 kilometer radius
  SERVICE wikibase:around {
      ?hospital wdt:P625 ?hospitalLocation.
      bd:serviceParam wikibase:center ?centerLocation.
      bd:serviceParam wikibase:radius "3".
  }

  #get all hospitals within the radius of our center
  {
    ?hospital wdt:P31 wd:Q16917; #hospital
  }
  UNION 
  { 
    ?hospital wdt:P31 wd:Q1774898; #clinic
  }
  UNION 
  { 
    ?hospital wdt:P31 wd:Q7309759; #rehabilitation hospital 
  }
  UNION 
  { 
    ?hospital wdt:P31 wd:Q644264; #children hospital
  }
  UNION 
  { 
    ?hospital wdt:P31 wd:Q1391390; #specialist hospital
  }
  UNION 
  { 
    ?hospital wdt:P31 wd:Q39364723; #hospital building 
  }


  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
  #calculate the distance between our center and each hospital
  BIND(geof:distance(?centerLocation, ?hospitalLocation) as ?dist)
} 
ORDER BY ?dist

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v2("?centerLocation") v5("?dist"):::projected v3("?hospital"):::projected v4("?hospitalLocation") c10(["wd:Q1774898"]):::iri c12(["wd:Q644264"]):::iri c1(["wd:Q647973"]):::iri c17(["en"]):::literal c13(["wd:Q1391390"]):::iri c14(["wd:Q39364723"]):::iri c4(["bd:serviceParam"]):::iri c7(["3"]):::literal c9(["wd:Q16917"]):::iri c11(["wd:Q7309759"]):::iri 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 union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; subgraph union1[" Union "] subgraph union1l[" "] style union1l fill:#abf,stroke-dasharray: 3 3; subgraph union2[" Union "] subgraph union2l[" "] style union2l fill:#abf,stroke-dasharray: 3 3; subgraph union3[" Union "] subgraph union3l[" "] style union3l fill:#abf,stroke-dasharray: 3 3; subgraph union4[" Union "] subgraph union4l[" "] style union4l fill:#abf,stroke-dasharray: 3 3; v3 --"wdt:P31"--> c14 end subgraph union4r[" "] style union4r fill:#abf,stroke-dasharray: 3 3; v3 --"wdt:P31"--> c13 end union4r <== or ==> union4l end end subgraph union3r[" "] style union3r fill:#abf,stroke-dasharray: 3 3; v3 --"wdt:P31"--> c12 end union3r <== or ==> union3l end end subgraph union2r[" "] style union2r fill:#abf,stroke-dasharray: 3 3; v3 --"wdt:P31"--> c11 end union2r <== or ==> union2l end end subgraph union1r[" "] style union1r fill:#abf,stroke-dasharray: 3 3; v3 --"wdt:P31"--> c10 end union1r <== or ==> union1l end end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v3 --"wdt:P31"--> c9 end union0r <== or ==> union0l end subgraph s2["http://wikiba.se/ontology#label"] style s2 stroke-width:4px; c4 --"wikibase:language"--> c17 end bind0[/"http://www.opengis.net/def/function/geosparql/distance(?centerLocation,?hospitalLocation)"/] v2 --o bind0 v4 --o bind0 bind0 --as--o v5