query-e218dd1caf975753f23665c9ce3fd744

rq turtle/ttl

Lower-Saxony, Germany

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", "?rgb"]}
SELECT DISTINCT ?coordinates ?line ?item ?itemLabel ?connectLabel ?image ?opening ?rgb




WHERE {
  {  {
  SELECT ?item (SAMPLE(?coordinates) AS ?coordinates) (SAMPLE(?image) AS ?image) (SAMPLE(?lat1) AS ?lat1) (SAMPLE(?lon1) AS ?lon1) (SAMPLE(?opening) AS ?opening) WHERE {
    {?item (wdt:P16|wdt:P361) wd:Q1552346 }
    UNION
    {?item (wdt:P16|wdt:P361) wd:Q449909 }
    UNION
    {?item (wdt:P16|wdt:P361) wd:Q1306245 }.
    ?item wdt:P625 ?coordinates  .
    ?item p:P625 / psv:P625 / wikibase:geoLatitude ?lat1 .
    ?item p:P625 / psv:P625 / wikibase:geoLongitude ?lon1 .
    #?item wdt:P465 ?rgb .
    OPTIONAL { ?item wdt:P18 ?image }.
    OPTIONAL { ?item wdt:P1619 ?opening }.
  } GROUP BY ?item
}}  UNION {  {
  SELECT ?line ?connect ?rgb WHERE {
     {
  SELECT ?item (SAMPLE(?coordinates) AS ?coordinates) (SAMPLE(?image) AS ?image) (SAMPLE(?lat1) AS ?lat1) (SAMPLE(?lon1) AS ?lon1) (SAMPLE(?opening) AS ?opening) WHERE {
    {?item (wdt:P16|wdt:P361) wd:Q1552346 }
    UNION
    {?item (wdt:P16|wdt:P361) wd:Q449909 }
    UNION
    {?item (wdt:P16|wdt:P361) wd:Q1306245 }.
    ?item wdt:P625 ?coordinates  .
    ?item p:P625 / psv:P625 / wikibase:geoLatitude ?lat1 .
    ?item p:P625 / psv:P625 / wikibase:geoLongitude ?lon1 .
    #?item wdt:P465 ?rgb .
    OPTIONAL { ?item wdt:P18 ?image }.
    OPTIONAL { ?item wdt:P1619 ?opening }.
  } GROUP BY ?item
}.
     {
  SELECT ?nextstation (SAMPLE(?lat2) AS ?lat2) (SAMPLE(?lon2) AS ?lon2) WHERE {
    {?nextstation (wdt:P16|wdt:P361) wd:Q1552346}
    UNION
    {?nextstation (wdt:P16|wdt:P361) wd:Q449909}
    UNION
    {?nextstation (wdt:P16|wdt:P361) wd:Q1306245} .
    ?nextstation p:P625 / psv:P625 / wikibase:geoLatitude ?lat2 .
    ?nextstation p:P625 / psv:P625 / wikibase:geoLongitude ?lon2 .
  } GROUP BY ?nextstation
}.
    ?item p:P197 ?nextstationstatement .
    ?nextstationstatement ps:P197 ?nextstation .
    {?nextstationstatement (pq:P81|pq:P1192) ?connect . ?connect (wdt:P16|wdt:P361) wd:Q1552346}
    UNION
    {?nextstationstatement (pq:P81|pq:P1192) ?connect . ?connect (wdt:P16|wdt:P361) wd:Q449909}
    UNION
    {?nextstationstatement (pq:P81|pq:P1192) ?connect . ?connect (wdt:P16|wdt:P361) wd:Q1306245} .
    ?connect wdt:P465 ?rgb .

    FILTER(STR(?item) < STR(?nextstation)) .   
    BIND(CONCAT('LINESTRING (', STR(?lon1), ' ', STR(?lat1), ',', STR(?lon2), ' ', STR(?lat2), ')') AS ?str) .
    BIND(STRDT(?str, 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; v11("?connect") v8("?coordinates"):::projected v8("?image"):::projected v1("?item"):::projected v8("?lat1") v10("?lat2") v14("?line"):::projected v8("?lon1") v10("?lon2") v7("?nextstation") v10("?nextstationstatement") v8("?opening"):::projected v12("?rgb"):::projected v13("?str") a1((" ")) a2((" ")) a3((" ")) a4((" ")) a5((" ")) a6((" ")) a7((" ")) a8((" ")) a9((" ")) a10((" ")) a11((" ")) a12((" ")) c5(["wd:Q1306245"]):::iri c4(["wd:Q449909"]):::iri c2(["wd:Q1552346"]):::iri c19(["bd:serviceParam"]):::iri c21(["#91;AUTO_LANGUAGE#93;,en"]):::literal subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; f0[["str(?item) < str(?nextstation)"]] f0 --> v1 f0 --> v7 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; v1 --"p:direct/P361"--> c5 end subgraph union3r[" "] style union3r fill:#abf,stroke-dasharray: 3 3; v1 --"p:direct/P16"--> c5 end union3r <== or ==> union3l end end subgraph union2r[" "] style union2r fill:#abf,stroke-dasharray: 3 3; subgraph union4[" Union "] subgraph union4l[" "] style union4l fill:#abf,stroke-dasharray: 3 3; v1 --"p:direct/P361"--> c4 end subgraph union4r[" "] style union4r fill:#abf,stroke-dasharray: 3 3; v1 --"p:direct/P16"--> c4 end union4r <== or ==> union4l end end union2r <== or ==> union2l end end subgraph union1r[" "] style union1r fill:#abf,stroke-dasharray: 3 3; subgraph union5[" Union "] subgraph union5l[" "] style union5l fill:#abf,stroke-dasharray: 3 3; v1 --"p:direct/P361"--> c2 end subgraph union5r[" "] style union5r fill:#abf,stroke-dasharray: 3 3; v1 --"p:direct/P16"--> c2 end union5r <== or ==> union5l end end union1r <== or ==> union1l end v1 --"p:direct/P625"--> v8 v1 --"p:P625"--> a5 a5 --"p:statement/value/P625"--> a6 a6 --"wikibase:geoLatitude"--> v8 v1 --"p:P625"--> a7 a7 --"p:statement/value/P625"--> a8 a8 --"wikibase:geoLongitude"--> v8 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v1 -."p:direct/P18".-> v8 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v1 -."p:direct/P1619".-> v8 end bind6[/"sample(?coordinates)"/] v8 --o bind6 bind6 --as--o v8 bind7[/"sample(?image)"/] v8 --o bind7 bind7 --as--o v8 bind8[/"sample(?lat1)"/] v8 --o bind8 bind8 --as--o v8 bind9[/"sample(?lon1)"/] v8 --o bind9 bind9 --as--o v8 bind10[/"sample(?opening)"/] v8 --o bind10 bind10 --as--o v8 subgraph union6[" Union "] subgraph union6l[" "] style union6l fill:#abf,stroke-dasharray: 3 3; subgraph union7[" Union "] subgraph union7l[" "] style union7l fill:#abf,stroke-dasharray: 3 3; subgraph union8[" Union "] subgraph union8l[" "] style union8l fill:#abf,stroke-dasharray: 3 3; v7 --"p:direct/P361"--> c5 end subgraph union8r[" "] style union8r fill:#abf,stroke-dasharray: 3 3; v7 --"p:direct/P16"--> c5 end union8r <== or ==> union8l end end subgraph union7r[" "] style union7r fill:#abf,stroke-dasharray: 3 3; subgraph union9[" Union "] subgraph union9l[" "] style union9l fill:#abf,stroke-dasharray: 3 3; v7 --"p:direct/P361"--> c4 end subgraph union9r[" "] style union9r fill:#abf,stroke-dasharray: 3 3; v7 --"p:direct/P16"--> c4 end union9r <== or ==> union9l end end union7r <== or ==> union7l end end subgraph union6r[" "] style union6r fill:#abf,stroke-dasharray: 3 3; subgraph union10[" Union "] subgraph union10l[" "] style union10l fill:#abf,stroke-dasharray: 3 3; v7 --"p:direct/P361"--> c2 end subgraph union10r[" "] style union10r fill:#abf,stroke-dasharray: 3 3; v7 --"p:direct/P16"--> c2 end union10r <== or ==> union10l end end union6r <== or ==> union6l end v7 --"p:P625"--> a9 a9 --"p:statement/value/P625"--> a10 a10 --"wikibase:geoLatitude"--> v10 v7 --"p:P625"--> a11 a11 --"p:statement/value/P625"--> a12 a12 --"wikibase:geoLongitude"--> v10 bind13[/"sample(?lat2)"/] v10 --o bind13 bind13 --as--o v10 bind14[/"sample(?lon2)"/] v10 --o bind14 bind14 --as--o v10 v1 --"p:P197"--> v10 v10 --"p:statement/P197"--> v7 subgraph union11[" Union "] subgraph union11l[" "] style union11l fill:#abf,stroke-dasharray: 3 3; subgraph union12[" Union "] subgraph union12l[" "] style union12l fill:#abf,stroke-dasharray: 3 3; subgraph union13[" Union "] subgraph union13l[" "] style union13l fill:#abf,stroke-dasharray: 3 3; v10 --"p:qualifier/P1192"--> v11 end subgraph union13r[" "] style union13r fill:#abf,stroke-dasharray: 3 3; v10 --"p:qualifier/P81"--> v11 end union13r <== or ==> union13l end subgraph union14[" Union "] subgraph union14l[" "] style union14l fill:#abf,stroke-dasharray: 3 3; v11 --"p:direct/P361"--> c5 end subgraph union14r[" "] style union14r fill:#abf,stroke-dasharray: 3 3; v11 --"p:direct/P16"--> c5 end union14r <== or ==> union14l end end subgraph union12r[" "] style union12r fill:#abf,stroke-dasharray: 3 3; subgraph union15[" Union "] subgraph union15l[" "] style union15l fill:#abf,stroke-dasharray: 3 3; v10 --"p:qualifier/P1192"--> v11 end subgraph union15r[" "] style union15r fill:#abf,stroke-dasharray: 3 3; v10 --"p:qualifier/P81"--> v11 end union15r <== or ==> union15l end subgraph union16[" Union "] subgraph union16l[" "] style union16l fill:#abf,stroke-dasharray: 3 3; v11 --"p:direct/P361"--> c4 end subgraph union16r[" "] style union16r fill:#abf,stroke-dasharray: 3 3; v11 --"p:direct/P16"--> c4 end union16r <== or ==> union16l end end union12r <== or ==> union12l end end subgraph union11r[" "] style union11r fill:#abf,stroke-dasharray: 3 3; subgraph union17[" Union "] subgraph union17l[" "] style union17l fill:#abf,stroke-dasharray: 3 3; v10 --"p:qualifier/P1192"--> v11 end subgraph union17r[" "] style union17r fill:#abf,stroke-dasharray: 3 3; v10 --"p:qualifier/P81"--> v11 end union17r <== or ==> union17l end subgraph union18[" Union "] subgraph union18l[" "] style union18l fill:#abf,stroke-dasharray: 3 3; v11 --"p:direct/P361"--> c2 end subgraph union18r[" "] style union18r fill:#abf,stroke-dasharray: 3 3; v11 --"p:direct/P16"--> c2 end union18r <== or ==> union18l end end union11r <== or ==> union11l end v11 --"p:direct/P465"--> v12 bind15[/"concat('LINESTRING (',str(?lon1),' ',str(?lat1),',',str(?lon2),' ',str(?lat2),')')"/] v8 --o bind15 v8 --o bind15 v10 --o bind15 v10 --o bind15 bind15 --as--o v13 bind16[/"STRDT(?str,'geo:wktLiteral')"/] v13 --o bind16 bind16 --as--o v14 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; subgraph union19[" Union "] subgraph union19l[" "] style union19l fill:#abf,stroke-dasharray: 3 3; subgraph union20[" Union "] subgraph union20l[" "] style union20l fill:#abf,stroke-dasharray: 3 3; subgraph union21[" Union "] subgraph union21l[" "] style union21l fill:#abf,stroke-dasharray: 3 3; v1 --"p:direct/P361"--> c5 end subgraph union21r[" "] style union21r fill:#abf,stroke-dasharray: 3 3; v1 --"p:direct/P16"--> c5 end union21r <== or ==> union21l end end subgraph union20r[" "] style union20r fill:#abf,stroke-dasharray: 3 3; subgraph union22[" Union "] subgraph union22l[" "] style union22l fill:#abf,stroke-dasharray: 3 3; v1 --"p:direct/P361"--> c4 end subgraph union22r[" "] style union22r fill:#abf,stroke-dasharray: 3 3; v1 --"p:direct/P16"--> c4 end union22r <== or ==> union22l end end union20r <== or ==> union20l end end subgraph union19r[" "] style union19r fill:#abf,stroke-dasharray: 3 3; subgraph union23[" Union "] subgraph union23l[" "] style union23l fill:#abf,stroke-dasharray: 3 3; v1 --"p:direct/P361"--> c2 end subgraph union23r[" "] style union23r fill:#abf,stroke-dasharray: 3 3; v1 --"p:direct/P16"--> c2 end union23r <== or ==> union23l end end union19r <== or ==> union19l end v1 --"p:direct/P625"--> v8 v1 --"p:P625"--> a1 a1 --"p:statement/value/P625"--> a2 a2 --"wikibase:geoLatitude"--> v8 v1 --"p:P625"--> a3 a3 --"p:statement/value/P625"--> a4 a4 --"wikibase:geoLongitude"--> v8 subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v1 -."p:direct/P18".-> v8 end subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; v1 -."p:direct/P1619".-> v8 end bind22[/"sample(?coordinates)"/] v8 --o bind22 bind22 --as--o v8 bind23[/"sample(?image)"/] v8 --o bind23 bind23 --as--o v8 bind24[/"sample(?lat1)"/] v8 --o bind24 bind24 --as--o v8 bind25[/"sample(?lon1)"/] v8 --o bind25 bind25 --as--o v8 bind26[/"sample(?opening)"/] v8 --o bind26 bind26 --as--o v8 end union0r <== or ==> union0l end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c19 --"wikibase:language"--> c21 end