query-3e05b17d00300b72e3fb5f3e5067f3a1

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#>
# Credit: User:Mahir256
#defaultView:Map{"hide":["?coordinates", "?line", "?rgb"]}
SELECT DISTINCT ?coordinates ?line ?sa ?saLabel ?connectLabel ?image ?code ?rgb





WHERE {
  {  {
  SELECT ?sa (SAMPLE(?coordinates) AS ?coordinates) (SAMPLE(?image) AS ?image) (sample(?lat1) as ?lat1) (sample(?lon1) as ?lon1) (sample(?code) as ?code) WHERE {
    {?sa wdt:P31 wd:Q1248784} UNION {?sa wdt:P31 wd:Q644371}
    ?sa wdt:P17 wd:Q668 .
    ?sa wdt:P625 ?coordinates  .
    ?sa p:P625 / psv:P625 / wikibase:geoLatitude ?lat1 .
    ?sa p:P625 / psv:P625 / wikibase:geoLongitude ?lon1 .
    OPTIONAL { ?sa wdt:P18 ?image }.
    OPTIONAL { ?sa wdt:P5696 ?code }.
  } GROUP BY ?sa
}}  UNION {  {
  SELECT ?line ?connect ("9B0058" as ?rgb) WHERE {
     {
  SELECT ?sa (SAMPLE(?coordinates) AS ?coordinates) (SAMPLE(?image) AS ?image) (sample(?lat1) as ?lat1) (sample(?lon1) as ?lon1) (sample(?code) as ?code) WHERE {
    {?sa wdt:P31 wd:Q1248784} UNION {?sa wdt:P31 wd:Q644371}
    ?sa wdt:P17 wd:Q668 .
    ?sa wdt:P625 ?coordinates  .
    ?sa p:P625 / psv:P625 / wikibase:geoLatitude ?lat1 .
    ?sa p:P625 / psv:P625 / wikibase:geoLongitude ?lon1 .
    OPTIONAL { ?sa wdt:P18 ?image }.
    OPTIONAL { ?sa wdt:P5696 ?code }.
  } GROUP BY ?sa
}.
     {
  SELECT ?da (sample(?lat2) as ?lat2) (sample(?lon2) as ?lon2) WHERE {
    {?da wdt:P31 wd:Q1248784} UNION {?da wdt:P31 wd:Q644371}
    ?sa wdt:P521 ?da.
    ?da p:P625 / psv:P625 / wikibase:geoLatitude ?lat2 .
    ?da p:P625 / psv:P625 / wikibase:geoLongitude ?lon2 .
  } GROUP BY ?da
}.
    ?sa p:P521 ?dastmt .
    ?dastmt ps:P521 ?da .
    ?dastmt pq:P137 ?connect .
#    FILTER(STR(?sa) < STR(?da)) .
    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; v7("?code"):::projected v11("?connect") v7("?coordinates"):::projected v7("?da") v10("?dastmt") v7("?image"):::projected v7("?lat1") v10("?lat2") v13("?line"):::projected v7("?lon1") v10("?lon2") v14("?rgb"):::projected v1("?sa"):::projected v12("?str") a1((" ")) a2((" ")) a3((" ")) a4((" ")) a5((" ")) a6((" ")) a7((" ")) a8((" ")) a9((" ")) a10((" ")) a11((" ")) a12((" ")) c3(["wd:Q644371"]):::iri c2(["wd:Q1248784"]):::iri c18(["bd:serviceParam"]):::iri c5(["wd:Q668"]):::iri c20(["#91;AUTO_LANGUAGE#93;,en"]):::literal 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; v1 --"p:direct/P31"--> c3 end subgraph union1r[" "] style union1r fill:#abf,stroke-dasharray: 3 3; v1 --"p:direct/P31"--> c2 end union1r <== or ==> union1l end v1 --"p:direct/P17"--> c5 v1 --"p:direct/P625"--> v7 v1 --"p:P625"--> a5 a5 --"p:statement/value/P625"--> a6 a6 --"wikibase:geoLatitude"--> v7 v1 --"p:P625"--> a7 a7 --"p:statement/value/P625"--> a8 a8 --"wikibase:geoLongitude"--> v7 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v1 -."p:direct/P18".-> v7 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v1 -."p:direct/P5696".-> v7 end bind5[/"sample(?coordinates)"/] v7 --o bind5 bind5 --as--o v7 bind6[/"sample(?image)"/] v7 --o bind6 bind6 --as--o v7 bind7[/"sample(?lat1)"/] v7 --o bind7 bind7 --as--o v7 bind8[/"sample(?lon1)"/] v7 --o bind8 bind8 --as--o v7 bind9[/"sample(?code)"/] v7 --o bind9 bind9 --as--o v7 subgraph union2[" Union "] subgraph union2l[" "] style union2l fill:#abf,stroke-dasharray: 3 3; v7 --"p:direct/P31"--> c3 end subgraph union2r[" "] style union2r fill:#abf,stroke-dasharray: 3 3; v7 --"p:direct/P31"--> c2 end union2r <== or ==> union2l end v1 --"p:direct/P521"--> v7 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 bind12[/"sample(?lat2)"/] v10 --o bind12 bind12 --as--o v10 bind13[/"sample(?lon2)"/] v10 --o bind13 bind13 --as--o v10 v1 --"p:P521"--> v10 v10 --"p:statement/P521"--> v7 v10 --"p:qualifier/P137"--> v11 bind14[/"concat('LINESTRING (',str(?lon1),' ',str(?lat1),',',str(?lon2),' ',str(?lat2),')')"/] v7 --o bind14 v7 --o bind14 v10 --o bind14 v10 --o bind14 bind14 --as--o v12 bind15[/"STRDT(?str,'geo:wktLiteral')"/] v12 --o bind15 bind15 --as--o v13 bind16[/"'9B0058'"/] bind16 --as--o v14 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; subgraph union3[" Union "] subgraph union3l[" "] style union3l fill:#abf,stroke-dasharray: 3 3; v1 --"p:direct/P31"--> c3 end subgraph union3r[" "] style union3r fill:#abf,stroke-dasharray: 3 3; v1 --"p:direct/P31"--> c2 end union3r <== or ==> union3l end v1 --"p:direct/P17"--> c5 v1 --"p:direct/P625"--> v7 v1 --"p:P625"--> a1 a1 --"p:statement/value/P625"--> a2 a2 --"wikibase:geoLatitude"--> v7 v1 --"p:P625"--> a3 a3 --"p:statement/value/P625"--> a4 a4 --"wikibase:geoLongitude"--> v7 subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v1 -."p:direct/P18".-> v7 end subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; v1 -."p:direct/P5696".-> v7 end bind22[/"sample(?coordinates)"/] v7 --o bind22 bind22 --as--o v7 bind23[/"sample(?image)"/] v7 --o bind23 bind23 --as--o v7 bind24[/"sample(?lat1)"/] v7 --o bind24 bind24 --as--o v7 bind25[/"sample(?lon1)"/] v7 --o bind25 bind25 --as--o v7 bind26[/"sample(?code)"/] v7 --o bind26 bind26 --as--o v7 end union0r <== or ==> union0l end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c18 --"wikibase:language"--> c20 end