query-7fba0281eceb5882e2380c5403ef4a6d
Propertiesinstance of (P31)subclass of (P279)twinned administrative body (P190)country (P17)coordinate location (P625)
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 geof: <http://www.opengis.net/def/function/geosparql/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?city ?cityLabel ?sister_city ?sister_cityLabel ?sister_city_countryLabel ?city_coords_ ?sister_city_coords_ ?distance
WHERE {
{
SELECT ?city ?sister_city (SAMPLE(?city_coords) AS ?city_coords_) (SAMPLE(?sister_city_coords) AS ?sister_city_coords_) ?sister_city_country WHERE {
?city wdt:P31/wdt:P279* wd:Q515;
wdt:P190 ?sister_city;
wdt:P17 wd:Q183.
OPTIONAL { ?city wdt:P625 ?city_coords. }
OPTIONAL { ?sister_city wdt:P625 ?sister_city_coords. }
OPTIONAL { ?sister_city wdt:P17 ?sister_city_country. }
}
GROUP BY ?city ?sister_city ?sister_city_country
}
BIND(geof:distance(?city_coords_, ?sister_city_coords_) AS ?distance)
SERVICE wikibase:label { bd:serviceParam wikibase:language "de,en". }
}
ORDER BY ?distance
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v2("?city"):::projected
v4("?city_coords")
v7("?city_coords_"):::projected
v9("?distance"):::projected
v3("?sister_city"):::projected
v5("?sister_city_coords")
v8("?sister_city_coords_"):::projected
v6("?sister_city_country")
a1((" "))
c9(["bd:serviceParam"]):::iri
c3(["wd:Q515"]):::iri
c6(["wd:Q183"]):::iri
c11(["de,en"]):::literal
v2 --"wdt:P31"--> a1
a1 --"wdt:P279"--> c3
v2 --"wdt:P190"--> v3
v2 --"wdt:P17"--> c6
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v2 -."wdt:P625".-> v4
end
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v3 -."wdt:P625".-> v5
end
subgraph optional2["(optional)"]
style optional2 fill:#bbf,stroke-dasharray: 5 5;
v3 -."wdt:P17".-> v6
end
bind2[/"sample(?city_coords)"/]
v4 --o bind2
bind2 --as--o v7
bind3[/"sample(?sister_city_coords)"/]
v5 --o bind3
bind3 --as--o v8
bind4[/"http://www.opengis.net/def/function/geosparql/distance(?city_coords_,?sister_city_coords_)"/]
v7 --o bind4
v8 --o bind4
bind4 --as--o v9
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c9 --"wikibase:language"--> c11
end