Description
Before you start
- I searched the existing issues and the roadmap and did not find a duplicate request.
What problem does this solve?
A classified raster with a colour table, such as slope classes or land cover, shows the right colours with the Colormap renderer. But the legend lists the raw values (1, 2, 3 …) instead of the class names. Neither the command line nor the project file offers a way to set them: layer.classStyle answers "this works on feature layers, not rasters".
Example: a slope map in 7 classes (0-5 %, 5-15 %, 15-30 %, 30-50 %, 50-70 %, 70-100 %, over 100 %) with its palette. The legend shows 1 to 7, so a reader cannot tell what each colour means.
Proposed solution
- Read the class names that GDAL writes for a band (
GDAL_METADATA/.aux.xmlcategory names, or theClass_Names/Valuecolumns of a raster attribute table). Use them as legend labels in the Colormap and Unique Values renderers. - Let
layer.classStylesetlabel(andcolor) on raster Unique Values and Colormap classes, as it already does for feature layers.
In v0.4.0 the legend label comes from fmt_num(*v) in crates/map/src/raster.rs (RasterRenderer::Colormap).
Estimated scope
Small to medium: reading the names from the .aux.xml sidecar, which #438 already reads, plus a label field on raster classes in the project format.
Alternatives considered
Polygonising the classes to use vector Unique Values works, but it makes a large layer for a display-only need.
Activity
GISspecialistAlejandraDuque commentedon Oct 26, 2026
I'll take the first part of this. Plan: read the
<CategoryNames>GDAL writes to a band's.aux.xmlinpam.rs, keep them on the band next to its description, and use them as the labels of the Colormap and Unique Values legend rows in the Layers pane, falling back to the value where a class has no name. With tests, and checked on the slope-class raster from the issue.Out of scope for this PR, unless you'd rather have them in it: raster attribute tables,
layer.classStyleon raster classes, the layout colour bar, and rasters converted through GDAL.feat(raster): label legend classes with the category names of the .au…
fix(data): attribute tables keep their rows' index, read unit bins, b…
fix(data): an attribute table with only a min or a max is a range tab…
feat(data): label a raster's classes from the attribute table in its …
elpidioassinaturas commentedon Nov 14, 2026
Another case for the second part of this issue (setting raster class labels without a sidecar), from a plugin. Checked on
mainatbf4884e2.The BrasilData plugin brings the Copernicus Global Land Cover 100 m (CLMS LC100, 23 classes) for the user's area. It reads a window of the COG with
layer.addUrl {bbox}, then runsraster.process clipandraster.projectonto the project grid. It styles the result withstyle.importQgisand a paletted QML in which every entry has a label:The colours are right, but the Layers pane and the layout legend show 20, 30, 40… The
.aux.xmlcategory names (#971) and the attribute table (#1892) don't help here. The layer is the in-memory output ofraster.project, so it has no sidecar, and a plugin can't write one.Today a command has no way to name the classes:
style.importQgisreads eachpaletteEntry'svalue,colorandalpha, but dropslabel(crates/map/src/qgis/raster.rs, the"paletted"arm). QGIS keeps it as the class label, and so does acolorRampEntrylabel in a discretesinglebandpseudocolor.layer.classStyleanswers "this works on feature layers, not rasters".raster.symbologyhas no labels parameter.Any one of these would do, in order of preference:
labelofpaletteEntry(and ofcolorRampEntry) from a QML as the class label.layer.classStyle {value, label, color?}on raster Unique Values and Colormap classes, as this issue proposes.labelsmap onraster.symbology {type: "unique"}, for example{"30": "Vegetação herbácea"}.The same need comes up in the plugin for the MapBiomas land-cover classes and the OPERA DIST-S1 disturbance status. Today the plugin polygonises the classes to get names into the legend, which is the workaround this issue already calls heavy.