query-c7b25e3e2c19cb2917738d5477189841

rq turtle/ttl

TODO

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX psv: <http://www.wikidata.org/prop/statement/value/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX bd: <http://www.bigdata.com/rdf#>
#defaultView:Map{"hide":["?coordinates", "?line"]}
SELECT DISTINCT ?coordinates ?line ?item ?itemLabel ?image ?opening WHERE {
  ?item wdt:P31/wdt:P279* wd:Q55488 ; # we get train stations
        wdt:P361 wd:Q260870 ;         # … that are part of the amsterdam metro
        wdt:P625 ?coordinates  ;      # … their coordinate
        wdt:P1619 ?opening  ;         # … and their opening date
        p:P197 ?nextstationstatement ;# …     the statements of their neighboor station(s)
        # (could be factorized
        #p:P197 [ ps:P197 ?nextstation ;           # … we also get all the neighboorstation(s) of one station
        #         pq:P81 / wdt:P361 wd:Q260870  ]. # … who have a transport line that is a part of the amsterdam metro       )

  OPTIONAL { ?item wdt:P18 ?image }.  # … and its image if he has one

  # (part that would be removed if factorized)
  ?nextstationstatement ps:P197 ?nextstation ; 
                        pq:P81 / wdt:P361 wd:Q260870  .

  FILTER(STR(?item) < STR(?nextstation)) . # making sure we draw only one line for each pair of neighboor station, 
                                           # (as P197 (neighboor station) is symmetric, we could have two results for each line :
                                           # 1) ?item = Qaaa and ?nextstation = Qbbb 
                                           # 2) ?item = Qbbb and ?nextstation = Qaaa
                                           # so we choose to keep only (arbitrarily) the first one to draw only one line

  ?item p:P625 / psv:P625 [ wikibase:geoLatitude ?lat1 ;  wikibase:geoLongitude ?lon1 ].      # the coordinates of one end of the line
  ?nextstation p:P625 / psv:P625 [ wikibase:geoLatitude ?lat2 ; wikibase:geoLongitude ?lon2 ].#               … of one the other end of the line

  # Building the « LINESTRING » instruction that will ask the view to draw a line frome one station to another, 
  # with the appropriate datatype (thanks to strdt : https://www.w3.org/TR/sparql11-query/#func-strdt )
  BIND(STRDT(CONCAT('LINESTRING (', STR(?lon1), ' ', STR(?lat1), ',', STR(?lon2), ' ', STR(?lat2), ')'), geo:wktLiteral) AS ?line)

  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("?coordinates"):::projected v6("?image"):::projected v1("?item"):::projected v7("?lat1") v9("?lat2") v11("?line"):::projected v8("?lon1") v10("?lon2") v2("?nextstation") v5("?nextstationstatement") v4("?opening"):::projected a1((" ")) a2((" ")) a4((" ")) a3((" ")) a6((" ")) a5((" ")) c5(["wd:Q260870"]):::iri c17(["bd:serviceParam"]):::iri c3(["wd:Q55488"]):::iri c19(["#91;AUTO_LANGUAGE#93;,en"]):::literal f0[["str(?item) < str(?nextstation)"]] f0 --> v1 f0 --> v2 v1 --"p:direct/P31"--> a1 a1 --"p:direct/P279"--> c3 v1 --"p:direct/P361"--> c5 v1 --"p:direct/P625"--> v3 v1 --"p:direct/P1619"--> v4 v1 --"p:P197"--> v5 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v1 -."p:direct/P18".-> v6 end v5 --"p:statement/P197"--> v2 v5 --"p:qualifier/P81"--> a2 a2 --"p:direct/P361"--> c5 a3 --"wikibase:geoLatitude"--> v7 a3 --"wikibase:geoLongitude"--> v8 v1 --"p:P625"--> a4 a4 --"p:statement/value/P625"--> a3 a5 --"wikibase:geoLatitude"--> v9 a5 --"wikibase:geoLongitude"--> v10 v2 --"p:P625"--> a6 a6 --"p:statement/value/P625"--> a5 bind1[/"STRDT(concat('LINESTRING (',str(?lon1),' ',str(?lat1),',',str(?lon2),' ',str(?lat2),')'),'geo:wktLiteral')"/] v8 --o bind1 v7 --o bind1 v10 --o bind1 v9 --o bind1 bind1 --as--o v11 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c17 --"wikibase:language"--> c19 end