query-528d2eff652f96b95235c5e502233833
Good example query with LINESTRING for every feature so it's easier for people to reproduce. That page doesn't contain a LINESTRING example. Wikidata:SPARQL query service/queries/examples were doing some nice hacking with the LINESTRING geo wktLiteral. I try to have at least one example at Jheald & Fnielsen phab:T177475In This is what I have right now. It needs a bit of tweaking and improvement, without making it hugely more complicated. It should be in the order of magnitude of 50 points and lines.
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"]}
SELECT DISTINCT ?coordinates ?line ?item ?itemLabel ?image ?opening WHERE {
?item wdt:P361 wd:Q260870 .
?item wdt:P31/wdt:P279* wd:Q55488 .
?item wdt:P625 ?coordinates .
OPTIONAL { ?item wdt:P18 ?image }.
?item wdt:P1619 ?opening .
?item p:P197 ?nextstationstatement .
?nextstationstatement ps:P197 ?nextstation .
?nextstationstatement pq:P81 ?connect . ?connect wdt:P361 wd:Q260870 .
FILTER(STR(?item) < STR(?nextstation)) .
?item p:P625 / psv:P625 / wikibase:geoLatitude ?lat1 .
?item p:P625 / psv:P625 / wikibase:geoLongitude ?lon1 .
?nextstation p:P625 / psv:P625 / wikibase:geoLatitude ?lat2 .
?nextstation p:P625 / psv:P625 / wikibase:geoLongitude ?lon2 .
BIND(STRDT(CONCAT('LINESTRING (', STR(?lon1), ' ', STR(?lat1), ',', STR(?lon2), ' ', STR(?lat2), ')'), 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("?connect")
v3("?coordinates"):::projected
v4("?image"):::projected
v1("?item"):::projected
v8("?lat1")
v10("?lat2")
v12("?line"):::projected
v9("?lon1")
v11("?lon2")
v2("?nextstation")
v6("?nextstationstatement")
v5("?opening"):::projected
a1((" "))
a2((" "))
a3((" "))
a4((" "))
a5((" "))
a6((" "))
a7((" "))
a8((" "))
a9((" "))
c2(["wd:Q260870"]):::iri
c17(["bd:serviceParam"]):::iri
c5(["wd:Q55488"]):::iri
c19(["#91;AUTO_LANGUAGE#93;,en"]):::literal
f0[["str(?item) < str(?nextstation)"]]
f0 --> v1
f0 --> v2
v1 --"p:direct/P361"--> c2
v1 --"p:direct/P31"--> a1
a1 --"p:direct/P279"--> c5
v1 --"p:direct/P625"--> v3
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v1 -."p:direct/P18".-> v4
end
v1 --"p:direct/P1619"--> v5
v1 --"p:P197"--> v6
v6 --"p:statement/P197"--> v2
v6 --"p:qualifier/P81"--> v7
v7 --"p:direct/P361"--> c2
v1 --"p:P625"--> a2
a2 --"p:statement/value/P625"--> a3
a3 --"wikibase:geoLatitude"--> v8
v1 --"p:P625"--> a4
a4 --"p:statement/value/P625"--> a5
a5 --"wikibase:geoLongitude"--> v9
v2 --"p:P625"--> a6
a6 --"p:statement/value/P625"--> a7
a7 --"wikibase:geoLatitude"--> v10
v2 --"p:P625"--> a8
a8 --"p:statement/value/P625"--> a9
a9 --"wikibase:geoLongitude"--> v11
bind1[/"STRDT(concat('LINESTRING (',str(?lon1),' ',str(?lat1),',',str(?lon2),' ',str(?lat2),')'),'geo:wktLiteral')"/]
v9 --o bind1
v8 --o bind1
v11 --o bind1
v10 --o bind1
bind1 --as--o v12
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c17 --"wikibase:language"--> c19
end