Closed trey-stafford closed 1 year ago
@trey-stafford I think this will be interesting to you.
While we are correctly setting "unit suffix" in our styles, it only applies to non-continuous legends. In the symbology menu, below the "classes" input field, there is a "Legend Settings..." button. Here you can enable/disable the continuous legend (enabled by default), or set a prefix or suffix specific to the continuous legend.
Among other things, the orientation of the legend can also be changed to "horizontal" here, which I think is a much better use of space in the Layer Properties menu.
We could validate that the "Label unit suffix" matches the "continuous legend suffix" for every style. We could also validate that continuous legends are set to horizontal :)
For future reference, the continuous legend was added in 3.18: https://gis.stackexchange.com/a/156722 (the author of the answer to this post is a QGIS developer, I didn't find a corresponding changelog entry in my quick search).
Here's the XML that sets the continuous legend on and sets the suffix:
<rampLegendSettings orientation="1" direction="0" maximumLabel="" suffix="%" useContinuousLegend="1" prefix="" minimumLabel="">
The XML in our current styles sets the suffix by baking it into the label
property of each item
element within a colorrampshader
element:
<item value="15" color="#040613" alpha="255" label="15 %"/>
<item value="15.3315" color="#050614" alpha="255" label="15.3315 %"/>
<item value="15.3315" color="#050614" alpha="255" label="15.3315 %"/>
<item value="15.663" color="#050715" alpha="255" label="15.663 %"/>
The problem is QGIS sometimes defaults to a continuous color ramp even if the style is built on a QGIS version before support for continuous color ramps were added. I think that happens when the "Mode" is set to "Continuous" in the symbology menu. But haven't figured out where that is in the XML.
"Mode is Continuous" appears to be represented by classificationMode="1"
on the colorrampshader
tag.
<colorrampshader clip="1" maximumValue="100" classificationMode="1" ...>
I think our validator logic should look like:
colorrampshader
's classificationMode
is 1
(continuous). If not, validation passes because we only care about preventing people from entering a "Label unit suffix" and incorrectly expecting it to display on a continuous legend.item
of the colorrampshader
has a suffix by seeing if the value
property and the label
property differ. If not, validation passes because we don't have any units in the current style. If so, extract the suffix and call it unit_suffix
.rampLegendSettings
element with a suffix
property which matches unit_suffix
and useContinuousLegend=1
. If so, validation passes because the continuous color ramp is correctly set.Style X's continuous legend is incorrectly configured. In QGIS >=3.28, edit this style in the layer symbology menu and ensure that the "Label unit suffix" exactly matches the "suffix" field in the "Legend Settings" menu.
?
Raster colormap legends in QGIS 3.28 look better than they had previously (shows a color ramp with max/min values instead of an entry for each discrete color step). However, I noticed that units suffix isn't showing up (e.g., for "Terrain models/Bedmachine/Ice thickness (150m)" should indicate "m" for meters after the min/max value).
Can we fix / change how the color ramp is displayed in the legend so that the units are shown? Maybe this is a bug w/ QGIS?