query-992a2291fe839ad2bf8e0299aa7b3974

rq turtle/ttl

Stations in Ontario closer than 10 km from a city of more than 100 000 inhabitants

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#>
# Stations in Ontario closer than 10 km from a city of more than 100 000 inhabitants
#defaultView:Map
SELECT DISTINCT ?city ?coordonn_es_g_ographiques WHERE {
  {
    # City/town: Q7930989  Airport: Q1248784 Port: Q44782
    SELECT ?city WHERE { ?city (wdt:P31/wdt:P279*) wd:Q7930989. }
  }
  ?city wdt:P131* wd:Q1904. # In Ontario

  # Filtering by population
  ?city wdt:P1082 ?population # Cities population
  FILTER (?population > 100000) .

  # Filtering by location
  ?city wdt:P625 ?cityLoc # Cities location
  SERVICE wikibase:around {
    ?station wdt:P625 ?location .
    bd:serviceParam wikibase:center ?cityLoc .
    bd:serviceParam wikibase:radius "10" . # within 10 km radius
  } .
   # is close from a Wx station
  FILTER EXISTS { ?station wdt:P31/wdt:P279* wd:Q190107 } .

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  OPTIONAL { ?city wdt:P625 ?coordonn_es_g_ographiques. }
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v3("?city"):::projected v4("?cityLoc") v6("?coordonn_es_g_ographiques"):::projected v5("?location") v2("?population") v1("?station") a2((" ")) a1((" ")) c5(["wd:Q7930989"]):::iri c7(["wd:Q1904"]):::iri c3(["wd:Q190107"]):::iri c11(["bd:serviceParam"]):::iri c17(["#91;AUTO_LANGUAGE#93;,en"]):::literal c14(["10"]):::literal f0[[" "]] subgraph f0e0["Exists Clause"] e0v1 --"wdt:P31"--> e0a1 e0a1 --"wdt:P279"--> e0c3 e0v1("?station"):::projected e0a1((" ")):::projected e0c3(["wd:Q190107"]):::iri end f0--EXISTS--> f0e0 f0 --> v1 f0 --> c1 f0 --> a1 f0 --> c2 f0 --> c3 v1 --"wdt:P31"--> a1 a1 --"wdt:P279"--> c3 f1[["?population > '100000^^xsd:integer'"]] f1 --> v2 v3 --"wdt:P31"--> a2 a2 --"wdt:P279"--> c5 v3 --"wdt:P131"--> c7 v3 --"wdt:P1082"--> v2 v3 --"wdt:P625"--> v4 subgraph s1["http://wikiba.se/ontology#around"] style s1 stroke-width:4px; v1 --"wdt:P625"--> v5 c11 --"wikibase:center"--> v4 c11 --"wikibase:radius"--> c14 end subgraph s2["http://wikiba.se/ontology#label"] style s2 stroke-width:4px; c11 --"wikibase:language"--> c17 end subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v3 -."wdt:P625".-> v6 end