query-c53c741804741e794b58dfdb286c7a0d
Full exampleUK cities with populations between 100,000 and 799,999 (excludes London and Birmingham, which are bigger than this).The second part finds the cities, with their populations in 100,000s; the INCLUDE statement then does a merge with the results of the first part, keeping values of ?colour from 1.0 to 7.0 and attaching hex colours to them, based on the colour progression defined in this item. , with ?n= 3 to generate hex codes for 7 colours from blue to red, matched to numbers 1.0 to 7.0named sub-queryThe first part of query uses the query code from the previous section as a
Use at
- https://query.wikidata.org/sparql
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
#defaultView:Map
SELECT DISTINCT ?item ?itemLabel ?pop ?coords ?rgb (?colour AS ?layer)
WHERE {
?item wdt:P31/wdt:P279* wd:Q515 .
?item wdt:P17 wd:Q145.
?item wdt:P1082 ?pop .
?item wdt:P625 ?coords .
BIND(xsd:float(floor(?pop / 100000)) AS ?colour) .
{
SELECT ?colour ?rgb WHERE {
VALUES ?sequence {wd:Q105849312} . # desired colour progression
VALUES ?n {3} . # desired no of points either side of centre -- in this case 3, to give numbers 1 to 7
?sequence p:P527 ?stmt .
?stmt pq:P1545 ?seq .
?stmt pq:P465 ?rgb .
?sequence p:P2670/pq:P1114 ?len .
BIND(((?len + 1.0)/2.0) AS ?centre) .
BIND (floor((?centre - 1.0) / xsd:float(?n)) AS ?step) .
BIND (?n + 1.0 + ((xsd:float(?seq) - ?centre) / xsd:float(?step)) AS ?colour) .
FILTER(?colour = floor(?colour))
FILTER(?colour >= 1)
FILTER(?colour <= 1 + 2* ?n)
} ORDER BY ?colour
}.
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} ORDER BY ?pop
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v11("?centre")
v13("?colour"):::projected
v3("?coords"):::projected
v2("?item"):::projected
v13("?layer")
v10("?len")
v7("?n")
v1("?pop"):::projected
v9("?rgb"):::projected
v8("?seq")
v6("?sequence")
v12("?step")
v7("?stmt")
a1((" "))
a2((" "))
c16(["bd:serviceParam"]):::iri
c3(["wd:Q515"]):::iri
c18(["#91;AUTO_LANGUAGE#93;,en"]):::literal
c5(["wd:Q145"]):::iri
v2 --"p:direct/P31"--> a1
a1 --"p:direct/P279"--> c3
v2 --"p:direct/P17"--> c5
v2 --"p:direct/P1082"--> v1
v2 --"p:direct/P625"--> v3
bind0[/"http://www.w3.org/2001/XMLSchema#float(numeric-floor(?pop / '100000^^xsd:integer'))"/]
v1 --o bind0
bind0 --as--o v13
f1[["?colour <= '1^^xsd:integer' + '2^^xsd:integer' * ?n"]]
f1 --> v13
f1 --> v7
f2[["?colour >= '1^^xsd:integer'"]]
f2 --> v13
f3[["?colour = numeric-floor(?colour)"]]
f3 --> v13
bind4[/VALUES ?sequence/]
bind4-->v6
bind40(["wd:Q105849312"])
bind40 --> bind4
bind5[/VALUES ?n/]
bind5-->v7
bind50(["3^^xsd:integer"])
bind50 --> bind5
v6 --"p:P527"--> v7
v7 --"p:qualifier/P1545"--> v8
v7 --"p:qualifier/P465"--> v9
v6 --"p:P2670"--> a2
a2 --"p:qualifier/P1114"--> v10
bind6[/"?len + '1.0^^xsd:decimal' / '2.0^^xsd:decimal'"/]
v10 --o bind6
bind6 --as--o v11
bind7[/"numeric-floor(?centre - '1.0^^xsd:decimal' / http://www.w3.org/2001/XMLSchema#float(?n))"/]
v11 --o bind7
v7 --o bind7
bind7 --as--o v12
bind8[/"?n + '1.0^^xsd:decimal' + http://www.w3.org/2001/XMLSchema#float(?seq) - ?centre / http://www.w3.org/2001/XMLSchema#float(?step)"/]
v7 --o bind8
v8 --o bind8
v11 --o bind8
v12 --o bind8
bind8 --as--o v13
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c16 --"wikibase:language"--> c18
end
bind9[/"?colour"/]
v13 --o bind9
bind9 --as--o v13