query-ff05d79662ccd83b58ceb02a13b23885
Adjacent Station with obligate connecting line and optional connecting service
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 rdfs: <http://www.w3.org/2000/01/rdf-schema#>
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#>
#defaultView:Map{"hide":["?coord1", "?coord2", "?line", "?rgb", "?coord1lon", "?coord1lat", "?coord2lon", "?coord2lat", "?str", "?stationType"]}
SELECT * WHERE {
{
VALUES ?stationType { wd:Q55488 wd:Q55678 wd:Q4663385 wd:Q65464941 }
?comm1 wdt:P31 ?stationType ;
wdt:P17 wd:Q40 ;
wdt:P625 ?coord1 ; wdt:P197 ?comm2.
OPTIONAL { ?comm1 wdt:P582|wdt:P576 ?endtime1. }
OPTIONAL { ?comm2 wdt:P582|wdt:P576 ?endtime2. }
?comm2 wdt:P625 ?coord2 .
?comm1 p:P625 [ ps:P625 []; psv:P625 [ wikibase:geoLongitude ?coord1lon; wikibase:geoLatitude ?coord1lat; ] ].
?comm2 p:P625 [ ps:P625 []; psv:P625 [ wikibase:geoLongitude ?coord2lon; wikibase:geoLatitude ?coord2lat; ] ].
?comm1 p:P197 ?adjStmt1. ?adjStmt1 pq:P81 ?conLine1. OPTIONAL { ?adjStmt1 pq:P1192 ?conService1. }
BIND(CONCAT('LINESTRING (', STR(?coord1lon), ' ', STR(?coord1lat), ',', STR(?coord2lon), ' ', STR(?coord2lat), ')') AS ?str) .
BIND(STRDT(?str, geo:wktLiteral) AS ?line).
BIND( IF(BOUND(?endtime1) || BOUND(?endtime2),"c2c2c2", "ff0033")as ?rgb)
BIND( IF(BOUND(?endtime1) || BOUND(?endtime2),"decomissioned", "in service")as ?layer)
?comm1 rdfs:label ?comm1Label. FILTER(LANG(?comm1Label)="[AUTO_LANGUAGE]").
?comm2 rdfs:label ?comm2Label. FILTER(LANG(?comm2Label)="[AUTO_LANGUAGE]").
}
}
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v14("?adjStmt1"):::projected
v4("?comm1"):::projected
v2("?comm1Label"):::projected
v6("?comm2"):::projected
v1("?comm2Label"):::projected
v15("?conLine1"):::projected
v16("?conService1"):::projected
v5("?coord1"):::projected
v11("?coord1lat"):::projected
v10("?coord1lon"):::projected
v9("?coord2"):::projected
v13("?coord2lat"):::projected
v12("?coord2lon"):::projected
v7("?endtime1"):::projected
v8("?endtime2"):::projected
v20("?layer"):::projected
v18("?line"):::projected
v19("?rgb"):::projected
v3("?stationType"):::projected
v17("?str"):::projected
a2((" "))
a1((" "))
a3((" "))
a4((" "))
a6((" "))
a5((" "))
c4(["wd:Q40"]):::iri
f0[["?comm2Label = '#91;AUTO_LANGUAGE#93;'"]]
f0 --> v1
f1[["?comm1Label = '#91;AUTO_LANGUAGE#93;'"]]
f1 --> v2
bind2[/VALUES ?stationType/]
bind2-->v3
bind20(["wd:Q55488"])
bind20 --> bind2
bind21(["wd:Q55678"])
bind21 --> bind2
bind22(["wd:Q4663385"])
bind22 --> bind2
bind23(["wd:Q65464941"])
bind23 --> bind2
v4 --"p:direct/P31"--> v3
v4 --"p:direct/P17"--> c4
v4 --"p:direct/P625"--> v5
v4 --"p:direct/P197"--> v6
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
subgraph union0[" Union "]
subgraph union0l[" "]
style union0l fill:#abf,stroke-dasharray: 3 3;
v4 -."p:direct/P576".-> v7
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
v4 --"p:direct/P582"--> v7
end
union0r <== or ==> union0l
end
end
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
subgraph union1[" Union "]
subgraph union1l[" "]
style union1l fill:#abf,stroke-dasharray: 3 3;
v6 -."p:direct/P576".-> v8
end
subgraph union1r[" "]
style union1r fill:#abf,stroke-dasharray: 3 3;
v6 --"p:direct/P582"--> v8
end
union1r <== or ==> union1l
end
end
v6 --"p:direct/P625"--> v9
a1 --"p:statement/P625"--> a2
a3 --"wikibase:geoLongitude"--> v10
a3 --"wikibase:geoLatitude"--> v11
a1 --"p:statement/value/P625"--> a3
v4 --"p:P625"--> a1
a4 --"p:statement/P625"--> a5
a6 --"wikibase:geoLongitude"--> v12
a6 --"wikibase:geoLatitude"--> v13
a4 --"p:statement/value/P625"--> a6
v6 --"p:P625"--> a4
v4 --"p:P197"--> v14
v14 --"p:qualifier/P81"--> v15
subgraph optional2["(optional)"]
style optional2 fill:#bbf,stroke-dasharray: 5 5;
v14 -."p:qualifier/P1192".-> v16
end
bind3[/"concat('LINESTRING (',str(?coord1lon),' ',str(?coord1lat),',',str(?coord2lon),' ',str(?coord2lat),')')"/]
v10 --o bind3
v11 --o bind3
v12 --o bind3
v13 --o bind3
bind3 --as--o v17
bind4[/"STRDT(?str,'geo:wktLiteral')"/]
v17 --o bind4
bind4 --as--o v18
bind5[/"if((bound(?endtime1) || bound(?endtime2)),'c2c2c2','ff0033')"/]
v7 --o bind5
v8 --o bind5
bind5 --as--o v19
bind6[/"if((bound(?endtime1) || bound(?endtime2)),'decomissioned','in service')"/]
v7 --o bind6
v8 --o bind6
bind6 --as--o v20
v4 --"rdfs:label"--> v2
v6 --"rdfs:label"--> v1