query-275a6c9c8f77198548ed49fe183db5f7
The heights of mountains in Switzerland
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 rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX psn: <http://www.wikidata.org/prop/statement/value-normalized/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
# The heights of mountains in Switzerland
#defaultView:Map{"hide":["?x_coords","?rgb"]}
SELECT ?x ?xLabel ?description ?x_coords ?rgb # determine the max and min values (used to calculate the spread
WHERE {
{
# extract the data
SELECT ?data ?x ?x_coords WHERE {
?x wdt:P31 wd:Q8502 .
?x p:P2044/psn:P2044 [
wikibase:quantityAmount ?data
] .
?x wdt:P17 wd:Q39 .
?x wdt:P625 ?x_coords .
}
} {
SELECT (MAX(?data) AS ?max_data) (MIN(?data) AS ?min_data) WHERE {
{
# extract the data
SELECT ?data ?x ?x_coords WHERE {
?x wdt:P31 wd:Q8502 .
?x p:P2044/psn:P2044 [
wikibase:quantityAmount ?data
] .
?x wdt:P17 wd:Q39 .
?x wdt:P625 ?x_coords .
}
}
}
}
?x rdfs:label ?xLabel. FILTER (LANG(?xLabel) = "en") .
BIND (CONCAT("The height of ", ?xLabel, " is about ", STR(ROUND(?data)), " metres" ) AS ?description)
BIND ( ?max_data - ?min_data AS ?spread )
BIND ( xsd:integer( 100 * (?data - ?min_data) / ?spread) AS ?percent ) # 0 -> 100
# some example hues 0:red, 20:orange, 50:yellow, 90:green, 180:cyan, 220:blue, 280:indigo, 330:violet, 340:red
# varying hue
# BIND ( 255 * ?percent / 100 + 0 AS ?hue )
# BIND (1 AS ?value) #
# BIND (1 AS ?saturation) . # 0 -> 1
# varying the hue's value
BIND ( (1 - ?percent / 100 + 0) AS ?value ) # to black
BIND ( 255 * ?percent / 100 + 0 AS ?hue )
BIND (1 AS ?saturation) . # 0 -> 1
# varying the hue's saturation
# BIND ( (1 - ?percent / 100 + 0) AS ?saturation ) # to -> white
# BIND (0 AS ?hue) # red
# BIND (1 AS ?value) . # 0 -> 1
# the following algorithm based on https://stackoverflow.com/questions/3018313/algorithm-to-convert-rgb-to-hsv-and-hsv-to-rgb-in-range-0-255-for-both
BIND ( ?hue / 60 AS ?hh )
BIND ( FLOOR (?hh) AS ?i ) .
BIND ( ?hh - ?i AS ?ff) .
BIND ( ?value * ( 1 - ?saturation ) AS ?p) .
BIND ( ?value * ( 1 - ( ?saturation * ?ff)) AS ?q ) .
BIND ( ?value * ( 1 - ( ?saturation * (1 - ?ff ))) AS ?t ) .
BIND ( COALESCE(
IF(?i = 0, ?value, 1/0),
IF(?i = 1, ?q, 1/0),
IF(?i = 2, ?p, 1/0),
IF(?i = 3, ?p, 1/0),
IF(?i = 4, ?t, 1/0),
IF(?i = 5, ?value, 1/0),
?value
) AS ?r )
BIND ( COALESCE(
IF(?i = 0, ?t, 1/0),
IF(?i = 1, ?value, 1/0),
IF(?i = 2, ?value, 1/0),
IF(?i = 3, ?q, 1/0),
IF(?i = 4, ?p, 1/0),
IF(?i = 5, ?p, 1/0),
?p
) AS ?g )
BIND ( COALESCE(
IF(?i = 0, ?p, 1/0),
IF(?i = 1, ?p, 1/0),
IF(?i = 2, ?t, 1/0),
IF(?i = 3, ?value, 1/0),
IF(?i = 4, ?value, 1/0),
IF(?i = 5, ?q, 1/0),
?q
) AS ?b )
BIND (FLOOR(255 * ?r) AS ?red)
BIND (FLOOR(255 * ?g) AS ?green)
BIND (FLOOR(255 * ?b) AS ?blue)
# red
BIND ( FLOOR (?red / 16) AS ?red_1 )
BIND ( COALESCE(
IF(?red_1 < 10, STR(?red_1), 1/0),
IF(?red_1 = 10, "a", 1/0),
IF(?red_1 = 11, "b", 1/0),
IF(?red_1 = 12, "c", 1/0),
IF(?red_1 = 13, "d", 1/0),
IF(?red_1 = 14, "e", 1/0),
IF(?red_1 = 15, "f", 1/0),
"ERROR"
) AS ?red_hex1 )
BIND (FLOOR(?red - (16 * xsd:integer( ?red / 16 ))) AS ?red_2)
BIND ( COALESCE(
IF(?red_2 < 10, STR(?red_2), 1/0),
IF(?red_2 = 10, "a", 1/0),
IF(?red_2 = 11, "b", 1/0),
IF(?red_2 = 12, "c", 1/0),
IF(?red_2 = 13, "d", 1/0),
IF(?red_2 = 14, "e", 1/0),
IF(?red_2 = 15, "f", 1/0),
"ERROR"
) AS ?red_hex2 )
BIND (CONCAT(STR(?red_hex1), STR(?red_hex2)) AS ?red_hex )
# green
BIND ( FLOOR (?green / 16) AS ?green_1 )
BIND ( COALESCE(
IF(?green_1 < 10, STR(?green_1), 1/0),
IF(?green_1 = 10, "a", 1/0),
IF(?green_1 = 11, "b", 1/0),
IF(?green_1 = 12, "c", 1/0),
IF(?green_1 = 13, "d", 1/0),
IF(?green_1 = 14, "e", 1/0),
IF(?green_1 = 15, "f", 1/0),
"ERROR"
) AS ?green_hex1 )
BIND (FLOOR(?green - (16 * xsd:integer( ?green / 16 ))) AS ?green_2)
BIND ( COALESCE(
IF(?green_2 < 10, STR(?green_2), 1/0),
IF(?green_2 = 10, "a", 1/0),
IF(?green_2 = 11, "b", 1/0),
IF(?green_2 = 12, "c", 1/0),
IF(?green_2 = 13, "d", 1/0),
IF(?green_2 = 14, "e", 1/0),
IF(?green_2 = 15, "f", 1/0),
"ERROR"
) AS ?green_hex2 )
BIND (CONCAT(STR(?green_hex1), STR(?green_hex2)) AS ?green_hex )
# blue
BIND ( FLOOR (?blue / 16) AS ?blue_1 )
BIND ( COALESCE(
IF(?blue_1 < 10, STR(?blue_1), 1/0),
IF(?blue_1 = 10, "a", 1/0),
IF(?blue_1 = 11, "b", 1/0),
IF(?blue_1 = 12, "c", 1/0),
IF(?blue_1 = 13, "d", 1/0),
IF(?blue_1 = 14, "e", 1/0),
IF(?blue_1 = 15, "f", 1/0),
"ERROR"
) AS ?blue_hex1 )
BIND (FLOOR(?blue - (16 * xsd:integer( ?blue / 16 ))) AS ?blue_2)
BIND ( COALESCE(
IF(?blue_2 < 10, STR(?blue_2), 1/0),
IF(?blue_2 = 10, "a", 1/0),
IF(?blue_2 = 11, "b", 1/0),
IF(?blue_2 = 12, "c", 1/0),
IF(?blue_2 = 13, "d", 1/0),
IF(?blue_2 = 14, "e", 1/0),
IF(?blue_2 = 15, "f", 1/0),
"ERROR"
) AS ?blue_hex2 )
BIND (CONCAT(STR(?blue_hex1), STR(?blue_hex2)) AS ?blue_hex )
BIND (CONCAT(STR(?red_hex), STR(?green_hex), STR(?blue_hex)) AS ?rgb)
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;
v21("?b")
v24("?blue")
v35("?blue_1")
v37("?blue_2")
v39("?blue_hex")
v36("?blue_hex1")
v38("?blue_hex2")
v3("?data")
v7("?description"):::projected
v15("?ff")
v20("?g")
v23("?green")
v30("?green_1")
v32("?green_2")
v34("?green_hex")
v31("?green_hex1")
v33("?green_hex2")
v13("?hh")
v11("?hue")
v14("?i")
v5("?max_data")
v6("?min_data")
v16("?p")
v9("?percent")
v17("?q")
v19("?r")
v22("?red")
v25("?red_1")
v27("?red_2")
v29("?red_hex")
v26("?red_hex1")
v28("?red_hex2")
v40("?rgb"):::projected
v12("?saturation")
v8("?spread")
v18("?t")
v10("?value")
v2("?x"):::projected
v1("?xLabel"):::projected
v4("?x_coords"):::projected
a2((" "))
a1((" "))
a4((" "))
a3((" "))
c8(["wd:Q39"]):::iri
c12(["bd:serviceParam"]):::iri
c14(["#91;AUTO_LANGUAGE#93;,en"]):::literal
c3(["wd:Q8502"]):::iri
f0[["?xLabel = 'en'"]]
f0 --> v1
v2 --"p:direct/P31"--> c3
a1 --"wikibase:quantityAmount"--> v3
v2 --"p:P2044"--> a2
a2 --"p:statement/value-normalized/P2044"--> a1
v2 --"p:direct/P17"--> c8
v2 --"p:direct/P625"--> v4
v2 --"p:direct/P31"--> c3
a3 --"wikibase:quantityAmount"--> v3
v2 --"p:P2044"--> a4
a4 --"p:statement/value-normalized/P2044"--> a3
v2 --"p:direct/P17"--> c8
v2 --"p:direct/P625"--> v4
bind3[/"max(?data)"/]
v3 --o bind3
bind3 --as--o v5
bind4[/"min(?data)"/]
v3 --o bind4
bind4 --as--o v6
v2 --"rdfs:label"--> v1
bind5[/"concat('The height of ',?xLabel,' is about ',str(numeric-round(?data)),' metres')"/]
v1 --o bind5
v3 --o bind5
bind5 --as--o v7
bind6[/"?max_data - ?min_data"/]
v5 --o bind6
v6 --o bind6
bind6 --as--o v8
bind7[/"http://www.w3.org/2001/XMLSchema#integer('100^^xsd:integer' * ?data - ?min_data / ?spread)"/]
v3 --o bind7
v6 --o bind7
v8 --o bind7
bind7 --as--o v9
bind8[/"'1^^xsd:integer' - ?percent / '100^^xsd:integer' + '0^^xsd:integer'"/]
v9 --o bind8
bind8 --as--o v10
bind9[/"'255^^xsd:integer' * ?percent / '100^^xsd:integer' + '0^^xsd:integer'"/]
v9 --o bind9
bind9 --as--o v11
bind10[/"'1^^xsd:integer'"/]
bind10 --as--o v12
bind11[/"?hue / '60^^xsd:integer'"/]
v11 --o bind11
bind11 --as--o v13
bind12[/"numeric-floor(?hh)"/]
v13 --o bind12
bind12 --as--o v14
bind13[/"?hh - ?i"/]
v13 --o bind13
v14 --o bind13
bind13 --as--o v15
bind14[/"?value * '1^^xsd:integer' - ?saturation"/]
v10 --o bind14
v12 --o bind14
bind14 --as--o v16
bind15[/"?value * '1^^xsd:integer' - ?saturation * ?ff"/]
v10 --o bind15
v12 --o bind15
v15 --o bind15
bind15 --as--o v17
bind16[/"?value * '1^^xsd:integer' - ?saturation * '1^^xsd:integer' - ?ff"/]
v10 --o bind16
v12 --o bind16
v15 --o bind16
bind16 --as--o v18
bind17[/"if(?i = '0^^xsd:integer',?value,'1^^xsd:integer' / '0^^xsd:integer')if(?i = '1^^xsd:integer',?q,'1^^xsd:integer' / '0^^xsd:integer')if(?i = '2^^xsd:integer',?p,'1^^xsd:integer' / '0^^xsd:integer')if(?i = '3^^xsd:integer',?p,'1^^xsd:integer' / '0^^xsd:integer')if(?i = '4^^xsd:integer',?t,'1^^xsd:integer' / '0^^xsd:integer')if(?i = '5^^xsd:integer',?value,'1^^xsd:integer' / '0^^xsd:integer')?value"/]
v14 --o bind17
v10 --o bind17
v17 --o bind17
v16 --o bind17
v18 --o bind17
bind17 --as--o v19
bind18[/"if(?i = '0^^xsd:integer',?t,'1^^xsd:integer' / '0^^xsd:integer')if(?i = '1^^xsd:integer',?value,'1^^xsd:integer' / '0^^xsd:integer')if(?i = '2^^xsd:integer',?value,'1^^xsd:integer' / '0^^xsd:integer')if(?i = '3^^xsd:integer',?q,'1^^xsd:integer' / '0^^xsd:integer')if(?i = '4^^xsd:integer',?p,'1^^xsd:integer' / '0^^xsd:integer')if(?i = '5^^xsd:integer',?p,'1^^xsd:integer' / '0^^xsd:integer')?p"/]
v14 --o bind18
v18 --o bind18
v10 --o bind18
v17 --o bind18
v16 --o bind18
bind18 --as--o v20
bind19[/"if(?i = '0^^xsd:integer',?p,'1^^xsd:integer' / '0^^xsd:integer')if(?i = '1^^xsd:integer',?p,'1^^xsd:integer' / '0^^xsd:integer')if(?i = '2^^xsd:integer',?t,'1^^xsd:integer' / '0^^xsd:integer')if(?i = '3^^xsd:integer',?value,'1^^xsd:integer' / '0^^xsd:integer')if(?i = '4^^xsd:integer',?value,'1^^xsd:integer' / '0^^xsd:integer')if(?i = '5^^xsd:integer',?q,'1^^xsd:integer' / '0^^xsd:integer')?q"/]
v14 --o bind19
v16 --o bind19
v18 --o bind19
v10 --o bind19
v17 --o bind19
bind19 --as--o v21
bind20[/"numeric-floor('255^^xsd:integer' * ?r)"/]
v19 --o bind20
bind20 --as--o v22
bind21[/"numeric-floor('255^^xsd:integer' * ?g)"/]
v20 --o bind21
bind21 --as--o v23
bind22[/"numeric-floor('255^^xsd:integer' * ?b)"/]
v21 --o bind22
bind22 --as--o v24
bind23[/"numeric-floor(?red / '16^^xsd:integer')"/]
v22 --o bind23
bind23 --as--o v25
bind24[/"if(?red_1 < '10^^xsd:integer',str(?red_1),'1^^xsd:integer' / '0^^xsd:integer')if(?red_1 = '10^^xsd:integer','a','1^^xsd:integer' / '0^^xsd:integer')if(?red_1 = '11^^xsd:integer','b','1^^xsd:integer' / '0^^xsd:integer')if(?red_1 = '12^^xsd:integer','c','1^^xsd:integer' / '0^^xsd:integer')if(?red_1 = '13^^xsd:integer','d','1^^xsd:integer' / '0^^xsd:integer')if(?red_1 = '14^^xsd:integer','e','1^^xsd:integer' / '0^^xsd:integer')if(?red_1 = '15^^xsd:integer','f','1^^xsd:integer' / '0^^xsd:integer')'ERROR'"/]
v25 --o bind24
bind24 --as--o v26
bind25[/"numeric-floor(?red - '16^^xsd:integer' * http://www.w3.org/2001/XMLSchema#integer(?red / '16^^xsd:integer'))"/]
v22 --o bind25
bind25 --as--o v27
bind26[/"if(?red_2 < '10^^xsd:integer',str(?red_2),'1^^xsd:integer' / '0^^xsd:integer')if(?red_2 = '10^^xsd:integer','a','1^^xsd:integer' / '0^^xsd:integer')if(?red_2 = '11^^xsd:integer','b','1^^xsd:integer' / '0^^xsd:integer')if(?red_2 = '12^^xsd:integer','c','1^^xsd:integer' / '0^^xsd:integer')if(?red_2 = '13^^xsd:integer','d','1^^xsd:integer' / '0^^xsd:integer')if(?red_2 = '14^^xsd:integer','e','1^^xsd:integer' / '0^^xsd:integer')if(?red_2 = '15^^xsd:integer','f','1^^xsd:integer' / '0^^xsd:integer')'ERROR'"/]
v27 --o bind26
bind26 --as--o v28
bind27[/"concat(str(?red_hex1),str(?red_hex2))"/]
v26 --o bind27
v28 --o bind27
bind27 --as--o v29
bind28[/"numeric-floor(?green / '16^^xsd:integer')"/]
v23 --o bind28
bind28 --as--o v30
bind29[/"if(?green_1 < '10^^xsd:integer',str(?green_1),'1^^xsd:integer' / '0^^xsd:integer')if(?green_1 = '10^^xsd:integer','a','1^^xsd:integer' / '0^^xsd:integer')if(?green_1 = '11^^xsd:integer','b','1^^xsd:integer' / '0^^xsd:integer')if(?green_1 = '12^^xsd:integer','c','1^^xsd:integer' / '0^^xsd:integer')if(?green_1 = '13^^xsd:integer','d','1^^xsd:integer' / '0^^xsd:integer')if(?green_1 = '14^^xsd:integer','e','1^^xsd:integer' / '0^^xsd:integer')if(?green_1 = '15^^xsd:integer','f','1^^xsd:integer' / '0^^xsd:integer')'ERROR'"/]
v30 --o bind29
bind29 --as--o v31
bind30[/"numeric-floor(?green - '16^^xsd:integer' * http://www.w3.org/2001/XMLSchema#integer(?green / '16^^xsd:integer'))"/]
v23 --o bind30
bind30 --as--o v32
bind31[/"if(?green_2 < '10^^xsd:integer',str(?green_2),'1^^xsd:integer' / '0^^xsd:integer')if(?green_2 = '10^^xsd:integer','a','1^^xsd:integer' / '0^^xsd:integer')if(?green_2 = '11^^xsd:integer','b','1^^xsd:integer' / '0^^xsd:integer')if(?green_2 = '12^^xsd:integer','c','1^^xsd:integer' / '0^^xsd:integer')if(?green_2 = '13^^xsd:integer','d','1^^xsd:integer' / '0^^xsd:integer')if(?green_2 = '14^^xsd:integer','e','1^^xsd:integer' / '0^^xsd:integer')if(?green_2 = '15^^xsd:integer','f','1^^xsd:integer' / '0^^xsd:integer')'ERROR'"/]
v32 --o bind31
bind31 --as--o v33
bind32[/"concat(str(?green_hex1),str(?green_hex2))"/]
v31 --o bind32
v33 --o bind32
bind32 --as--o v34
bind33[/"numeric-floor(?blue / '16^^xsd:integer')"/]
v24 --o bind33
bind33 --as--o v35
bind34[/"if(?blue_1 < '10^^xsd:integer',str(?blue_1),'1^^xsd:integer' / '0^^xsd:integer')if(?blue_1 = '10^^xsd:integer','a','1^^xsd:integer' / '0^^xsd:integer')if(?blue_1 = '11^^xsd:integer','b','1^^xsd:integer' / '0^^xsd:integer')if(?blue_1 = '12^^xsd:integer','c','1^^xsd:integer' / '0^^xsd:integer')if(?blue_1 = '13^^xsd:integer','d','1^^xsd:integer' / '0^^xsd:integer')if(?blue_1 = '14^^xsd:integer','e','1^^xsd:integer' / '0^^xsd:integer')if(?blue_1 = '15^^xsd:integer','f','1^^xsd:integer' / '0^^xsd:integer')'ERROR'"/]
v35 --o bind34
bind34 --as--o v36
bind35[/"numeric-floor(?blue - '16^^xsd:integer' * http://www.w3.org/2001/XMLSchema#integer(?blue / '16^^xsd:integer'))"/]
v24 --o bind35
bind35 --as--o v37
bind36[/"if(?blue_2 < '10^^xsd:integer',str(?blue_2),'1^^xsd:integer' / '0^^xsd:integer')if(?blue_2 = '10^^xsd:integer','a','1^^xsd:integer' / '0^^xsd:integer')if(?blue_2 = '11^^xsd:integer','b','1^^xsd:integer' / '0^^xsd:integer')if(?blue_2 = '12^^xsd:integer','c','1^^xsd:integer' / '0^^xsd:integer')if(?blue_2 = '13^^xsd:integer','d','1^^xsd:integer' / '0^^xsd:integer')if(?blue_2 = '14^^xsd:integer','e','1^^xsd:integer' / '0^^xsd:integer')if(?blue_2 = '15^^xsd:integer','f','1^^xsd:integer' / '0^^xsd:integer')'ERROR'"/]
v37 --o bind36
bind36 --as--o v38
bind37[/"concat(str(?blue_hex1),str(?blue_hex2))"/]
v36 --o bind37
v38 --o bind37
bind37 --as--o v39
bind38[/"concat(str(?red_hex),str(?green_hex),str(?blue_hex))"/]
v29 --o bind38
v34 --o bind38
v39 --o bind38
bind38 --as--o v40
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c12 --"wikibase:language"--> c14
end