query-4f642a999f29b0d6079718aa18680254
TODO
Use at
- https://query.wikidata.org/sparql
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(?lat1) as ?lat1) (sample(?lon1) as ?lon1) WHERE {
?item wdt:P31 wd:Q928830 .
?item wdt:P17 wd:Q142.
?item wdt:P625 ?coordinates .
?item p:P625 / psv:P625 / wikibase:geoLatitude ?lat1 .
?item p:P625 / psv:P625 / wikibase:geoLongitude ?lon1 .
MINUS { ?item (wdt:P576|wdt:P582|wdt:P3999) ?dispar. }
MINUS { ?item wdt:P5817 [] . }
} GROUP BY ?item
}} UNION { {
SELECT ?line ?connect ?rgb WHERE {
{
SELECT ?item (SAMPLE(?coordinates) AS ?coordinates) (sample(?lat1) as ?lat1) (sample(?lon1) as ?lon1) WHERE {
?item wdt:P31 wd:Q928830 .
?item wdt:P17 wd:Q142.
?item wdt:P625 ?coordinates .
?item p:P625 / psv:P625 / wikibase:geoLatitude ?lat1 .
?item p:P625 / psv:P625 / wikibase:geoLongitude ?lon1 .
MINUS { ?item (wdt:P576|wdt:P582|wdt:P3999) ?dispar. }
MINUS { ?item wdt:P5817 [] . }
} GROUP BY ?item
}.
{
SELECT ?nextstation (sample(?lat2) as ?lat2) (sample(?lon2) as ?lon2) WHERE {
?nextstation wdt:P31 wd:Q928830 .
?nextstation wdt:P17 wd:Q142.
?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 ?connect .
MINUS {?nextstationstatement pq:P5817 wd:Q12377751 .}
?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;
v10("?connect")
v7("?coordinates"):::projected
v5("?dispar")
v1("?item"):::projected
v7("?lat1")
v9("?lat2")
v13("?line"):::projected
v7("?lon1")
v9("?lon2")
v6("?nextstation")
v9("?nextstationstatement")
v11("?rgb"):::projected
v12("?str")
a5((" "))
a10((" "))
a1((" "))
a2((" "))
a3((" "))
a4((" "))
a6((" "))
a7((" "))
a8((" "))
a9((" "))
a11((" "))
a12((" "))
a13((" "))
a14((" "))
c2(["wd:Q928830"]):::iri
c21(["bd:serviceParam"]):::iri
c23(["#91;AUTO_LANGUAGE#93;,en"]):::literal
c18(["wd:Q12377751"]):::iri
c4(["wd:Q142"]):::iri
subgraph union0[" Union "]
subgraph union0l[" "]
style union0l fill:#abf,stroke-dasharray: 3 3;
f0[["str(?item) < str(?nextstation)"]]
f0 --> v1
f0 --> v6
v1 --"p:direct/P31"--> c2
v1 --"p:direct/P17"--> c4
v1 --"p:direct/P625"--> v7
v1 --"p:P625"--> a6
a6 --"p:statement/value/P625"--> a7
a7 --"wikibase:geoLatitude"--> v7
v1 --"p:P625"--> a8
a8 --"p:statement/value/P625"--> a9
a9 --"wikibase:geoLongitude"--> v7
subgraph minus1["MINUS"]
style minus1 stroke-width:6px,fill:pink,stroke:red;
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;
v1 --"p:direct/P3999"--> v5
end
subgraph union2r[" "]
style union2r fill:#abf,stroke-dasharray: 3 3;
v1 --"p:direct/P582"--> v5
end
union2r <== or ==> union2l
end
end
subgraph union1r[" "]
style union1r fill:#abf,stroke-dasharray: 3 3;
v1 --"p:direct/P576"--> v5
end
union1r <== or ==> union1l
end
end
subgraph minus2["MINUS"]
style minus2 stroke-width:6px,fill:pink,stroke:red;
v1 --"p:direct/P5817"--> a10
end
bind6[/"sample(?coordinates)"/]
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
v6 --"p:direct/P31"--> c2
v6 --"p:direct/P17"--> c4
v6 --"p:P625"--> a11
a11 --"p:statement/value/P625"--> a12
a12 --"wikibase:geoLatitude"--> v9
v6 --"p:P625"--> a13
a13 --"p:statement/value/P625"--> a14
a14 --"wikibase:geoLongitude"--> v9
bind11[/"sample(?lat2)"/]
v9 --o bind11
bind11 --as--o v9
bind12[/"sample(?lon2)"/]
v9 --o bind12
bind12 --as--o v9
v1 --"p:P197"--> v9
v9 --"p:statement/P197"--> v6
v9 --"p:qualifier/P81"--> v10
subgraph minus13["MINUS"]
style minus13 stroke-width:6px,fill:pink,stroke:red;
v9 --"p:qualifier/P5817"--> c18
end
v10 --"p:direct/P465"--> v11
bind14[/"concat('LINESTRING (',str(?lon1),' ',str(?lat1),',',str(?lon2),' ',str(?lat2),')')"/]
v7 --o bind14
v7 --o bind14
v9 --o bind14
v9 --o bind14
bind14 --as--o v12
bind15[/"STRDT(?str,'geo:wktLiteral')"/]
v12 --o bind15
bind15 --as--o v13
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
v1 --"p:direct/P31"--> c2
v1 --"p:direct/P17"--> c4
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 minus16["MINUS"]
style minus16 stroke-width:6px,fill:pink,stroke:red;
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;
v1 --"p:direct/P3999"--> v5
end
subgraph union4r[" "]
style union4r fill:#abf,stroke-dasharray: 3 3;
v1 --"p:direct/P582"--> v5
end
union4r <== or ==> union4l
end
end
subgraph union3r[" "]
style union3r fill:#abf,stroke-dasharray: 3 3;
v1 --"p:direct/P576"--> v5
end
union3r <== or ==> union3l
end
end
subgraph minus17["MINUS"]
style minus17 stroke-width:6px,fill:pink,stroke:red;
v1 --"p:direct/P5817"--> a5
end
bind21[/"sample(?coordinates)"/]
v7 --o bind21
bind21 --as--o v7
bind22[/"sample(?lat1)"/]
v7 --o bind22
bind22 --as--o v7
bind23[/"sample(?lon1)"/]
v7 --o bind23
bind23 --as--o v7
end
union0r <== or ==> union0l
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c21 --"wikibase:language"--> c23
end