query-eb52f18aad50f21618c0fb1a6637f44c
Beautify this queryHello! I'm playing a little bit with twinned cities and I have built a query to show all twinned cities of Basque municipalities connected with lines. The result is pretty... great and ridiculous. Greatculous! If anyone comes with a better way of visualizing this, it would be awesome!
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 p: <http://www.wikidata.org/prop/>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX bd: <http://www.bigdata.com/rdf#>
#defaultView:Map{"hide":["?coord1", "?coord2", "?line"]}
SELECT DISTINCT ?item ?itemLabel ?hiri_senidetuak ?hiri_senidetuakLabel ?coord1 ?coord2 ?line WHERE {
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
{ ?item wdt:P31 wd:Q2074737. }
UNION
{ ?item wdt:P31 wd:Q484170. }
?item (wdt:P131/(wdt:P131*)/^wdt:P527) wd:Q47588.
?item wdt:P190 ?hiri_senidetuak.
?item wdt:P625 ?coord1.
?hiri_senidetuak wdt:P625 ?coord2.
?item p:P625 [ ps:P625 []; psv:P625 [ wikibase:geoLongitude ?coord1lon; wikibase:geoLatitude ?coord1lat; ] ].
?hiri_senidetuak p:P625 [ ps:P625 []; psv:P625 [ wikibase:geoLongitude ?coord2lon; wikibase:geoLatitude ?coord2lat; ] ].
BIND(CONCAT('LINESTRING (', STR(?coord1lon), ' ', STR(?coord1lat), ',', STR(?coord2lon), ' ', STR(?coord2lat), ')') AS ?str) .
BIND(STRDT(?str, geo:wktLiteral) AS ?line)
}
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v3("?coord1"):::projected
v6("?coord1lat")
v5("?coord1lon")
v4("?coord2"):::projected
v8("?coord2lat")
v7("?coord2lon")
v2("?hiri_senidetuak"):::projected
v1("?item"):::projected
v10("?line"):::projected
v9("?str")
a4((" "))
a1((" "))
a2((" "))
a3((" "))
a5((" "))
a6((" "))
a8((" "))
a7((" "))
c6(["wd:Q2074737"]):::iri
c9(["wd:Q47588"]):::iri
c2(["bd:serviceParam"]):::iri
c4(["#91;AUTO_LANGUAGE#93;,en"]):::literal
c7(["wd:Q484170"]):::iri
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c2 --"wikibase:language"--> c4
end
subgraph union0[" Union "]
subgraph union0l[" "]
style union0l fill:#abf,stroke-dasharray: 3 3;
v1 --"p:direct/P31"--> c7
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
v1 --"p:direct/P31"--> c6
end
union0r <== or ==> union0l
end
v1 --"p:direct/P131"--> a1
a1 --"p:direct/P131"--> a2
c9 --"p:direct/P527"--> a2
v1 --"p:direct/P190"--> v2
v1 --"p:direct/P625"--> v3
v2 --"p:direct/P625"--> v4
a3 --"p:statement/P625"--> a4
a5 --"wikibase:geoLongitude"--> v5
a5 --"wikibase:geoLatitude"--> v6
a3 --"p:statement/value/P625"--> a5
v1 --"p:P625"--> a3
a6 --"p:statement/P625"--> a7
a8 --"wikibase:geoLongitude"--> v7
a8 --"wikibase:geoLatitude"--> v8
a6 --"p:statement/value/P625"--> a8
v2 --"p:P625"--> a6
bind0[/"concat('LINESTRING (',str(?coord1lon),' ',str(?coord1lat),',',str(?coord2lon),' ',str(?coord2lat),')')"/]
v5 --o bind0
v6 --o bind0
v7 --o bind0
v8 --o bind0
bind0 --as--o v9
bind1[/"STRDT(?str,'geo:wktLiteral')"/]
v9 --o bind1
bind1 --as--o v10