query-b2d1f6e1eb20432978b0609b839070bf
Collapsing query ). https://w.wiki/5jBW , especially when used with a map-plotting query like https://w.wiki/5jC5 mileage measured along the track. It can be quite helpful in finding stations with the wrong coordinates. (As also is the query's big brother (P6710)linear reference Here's a query to compare how apart stations are from a particular station according to their coordinates, compared to how far they are apart according to a
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 ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX geof: <http://www.opengis.net/def/function/geosparql/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?ratio ?item2 ?item2Label ?dist ?mileage_diff ?section ?lin ?lin2 ?sectionLabel
WHERE {
VALUES ?item {wd:Q2525068} .
{
SELECT ?item ?section ?elr ?lin ?itemLoc WHERE {
?item p:P795 ?stmt .
?stmt ps:P795 ?section .
?section wdt:P10271 ?elr .
?stmt pq:P6710 ?lin .
?item wdt:P625 ?itemLoc .
}
}.
?item2 wdt:P795 ?section .
FILTER (?item != ?item2) .
{
SELECT (?item AS ?item2) ?section (?lin AS ?lin2) (?itemLoc AS ?item2Loc) WHERE {
{
SELECT ?item ?section ?elr ?lin ?itemLoc WHERE {
?item p:P795 ?stmt .
?stmt ps:P795 ?section .
?section wdt:P10271 ?elr .
?stmt pq:P6710 ?lin .
?item wdt:P625 ?itemLoc .
}
}.
}
}
BIND ((geof:distance(?itemLoc, ?item2Loc) / 1.609) AS ?dist) .
BIND (abs(?lin - ?lin2) AS ?mileage_diff) .
BIND (?dist / ?mileage_diff AS ?ratio) .
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } .
}
ORDER BY ?lin2
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v10("?dist"):::projected
v6("?elr")
v4("?item")
v9("?item2"):::projected
v9("?item2Loc")
v8("?itemLoc")
v7("?lin"):::projected
v9("?lin2"):::projected
v11("?mileage_diff"):::projected
v12("?ratio"):::projected
v5("?section"):::projected
v4("?stmt")
c8(["bd:serviceParam"]):::iri
c10(["#91;AUTO_LANGUAGE#93;,en"]):::literal
f0[["?item != ?item2"]]
f0 --> v4
f0 --> v9
bind1[/VALUES ?item/]
bind1-->v4
bind10(["wd:Q2525068"])
bind10 --> bind1
v4 --"p:P795"--> v4
v4 --"p:statement/P795"--> v5
v5 --"p:direct/P10271"--> v6
v4 --"p:qualifier/P6710"--> v7
v4 --"p:direct/P625"--> v8
v9 --"p:direct/P795"--> v5
v4 --"p:P795"--> v4
v4 --"p:statement/P795"--> v5
v5 --"p:direct/P10271"--> v6
v4 --"p:qualifier/P6710"--> v7
v4 --"p:direct/P625"--> v8
bind2[/"?item"/]
v4 --o bind2
bind2 --as--o v9
bind3[/"?lin"/]
v7 --o bind3
bind3 --as--o v9
bind4[/"?itemLoc"/]
v8 --o bind4
bind4 --as--o v9
bind5[/"http://www.opengis.net/def/function/geosparql/distance(?itemLoc,?item2Loc) / '1.609^^xsd:decimal'"/]
v8 --o bind5
v9 --o bind5
bind5 --as--o v10
bind6[/"numeric-abs(?lin - ?lin2)"/]
v7 --o bind6
v9 --o bind6
bind6 --as--o v11
bind7[/"?dist / ?mileage_diff"/]
v10 --o bind7
v11 --o bind7
bind7 --as--o v12
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c8 --"wikibase:language"--> c10
end