query-15a5daef5ac55fddb41bf781a5fd8af4
Ymblanter
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 p: <http://www.wikidata.org/prop/>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
# Based on a query by James Heald
#defaultView:Map
SELECT ?line (COUNT (?line) AS ?layer)
WHERE
{
{
SELECT DISTINCT ?station
WHERE
{
VALUES ?stationtype { wd:Q55678 wd:Q55488 }
?station wdt:P17 wd:Q159 . # In Russia
?station wdt:P31 / wdt:P279* ?stationtype . # Instances of railway station
}
} ?station wdt:P197 ?next .
?station p:P625/psv:P625/wikibase:geoLatitude ?lat1 ;
p:P625/psv:P625/wikibase:geoLongitude ?lon1 .
?next p:P625/psv:P625/wikibase:geoLatitude ?lat2 ;
p:P625/psv:P625/wikibase:geoLongitude ?lon2 .
BIND(STRDT(IF(?lat1 < ?lat2,
CONCAT('LINESTRING(', STR(?lon1), ' ', STR(?lat1), ',', STR(?lon2), ' ', STR(?lat2), ')'),
CONCAT('LINESTRING(', STR(?lon2), ' ', STR(?lat2), ',', STR(?lon1), ' ', STR(?lat1), ')')),
geo:wktLiteral) AS ?line)
}
GROUP BY ?line
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v4("?lat1")
v6("?lat2")
v9("?layer")
v8("?line"):::projected
v5("?lon1")
v7("?lon2")
v3("?next")
v2("?station")
v1("?stationtype")
a1((" "))
a2((" "))
a3((" "))
a4((" "))
a5((" "))
a6((" "))
a7((" "))
a8((" "))
a9((" "))
c2(["wd:Q159"]):::iri
bind0[/VALUES ?stationtype/]
bind0-->v1
bind00(["wd:Q55678"])
bind00 --> bind0
bind01(["wd:Q55488"])
bind01 --> bind0
v2 --"p:direct/P17"--> c2
v2 --"p:direct/P31"--> a1
a1 --"p:direct/P279"--> v1
v2 --"p:direct/P197"--> v3
v2 --"p:P625"--> a2
a2 --"p:statement/value/P625"--> a3
a3 --"wikibase:geoLatitude"--> v4
v2 --"p:P625"--> a4
a4 --"p:statement/value/P625"--> a5
a5 --"wikibase:geoLongitude"--> v5
v3 --"p:P625"--> a6
a6 --"p:statement/value/P625"--> a7
a7 --"wikibase:geoLatitude"--> v6
v3 --"p:P625"--> a8
a8 --"p:statement/value/P625"--> a9
a9 --"wikibase:geoLongitude"--> v7
bind1[/"STRDT(if(?lat1 < ?lat2,concat('LINESTRING(',str(?lon1),' ',str(?lat1),',',str(?lon2),' ',str(?lat2),')'),concat('LINESTRING(',str(?lon2),' ',str(?lat2),',',str(?lon1),' ',str(?lat1),')')),'geo:wktLiteral')"/]
v4 --o bind1
v6 --o bind1
v5 --o bind1
v7 --o bind1
bind1 --as--o v8
bind3[/"count(?line)"/]
v8 --o bind3
bind3 --as--o v9