Repository navigation
Closed
Description
The problem
The Layers pane lists a classified raster's classes: a swatch and a label for each class of a Colormap, Unique Values or Classify renderer (RasterLayer::legend in crates/map/src/raster.rs). A layout legend leaves every raster out. Both legend_rows and shown_legends in crates/render/src/layout.rs filter !l.is_raster() (main b00a2b3).
So a land-cover map, a soil-class map or a slope-class map has no key on the sheet:
layout.publication: measures the legend without the raster. With nothing else on the map, it makes an empty box with only the title.allClasses: true: changes nothing.- Colorbar: covers rasters on a ramp only, not classes.
Reproduced on main (b00a2b3, with #1581) with the BrasilData plugin 0.1.25:
- Clip MapBiomas 2024 to Viçosa (MG). The result is a UInt8 raster with the file's colour table, Colormap renderer, 11 classes.
- Run
layout.publication. - The legend box reads "Classes do MapBiomas" (the title the plugin gives it) and nothing under it.
The only workaround today is to polygonise the classes and dissolve them by value, so the legend gets a vector Unique Values layer. BrasilData now does this:
- Speed: for one municipality (600,000 cells) it adds a few seconds to the command.
- Size: it adds 6 MB of geometry to the project, only for the key.
Choices in this proposal
- Which rasters: a raster whose renderer has classes (Colormap, Unique Values, Classify) gets its rows in the legend, under its name, like a vector layer. The rows are the ones the Layers pane already draws (
RasterLayer::legend): a filled swatch and the label. The label is the class name from the file when there is one, else the value. [Feature]: Raster legend labels from class names (colour table / RAT), and editable raster class labels #889 can improve those labels for both places at once. - Rasters left out as now:
- Stretch and shaded relief: the colorbar is their key.
- RGB composites: their channels are not a key a reader needs.
- Which classes: with
allClasses: false(the default), the classes in the raster's statistics (stats.categories), without the values its mask hides. WithallClasses: true, every entry of the renderer, for a Unique Values or Classify raster. A Colormap raster's 256-entry palette has no meaningful "all", so it lists its categories either way.- Rejected: only the classes the frame draws. For a raster this needs a scan of the frame's window on every redraw. The categories are already computed and match what the Layers pane shows.
- Order: the renderer's order (the colour table's values, ascending, or the Unique Values classes as listed).
excludeandhideOther: they work by layer name as they do for vector layers.layout.publication: it measures these rows with the others (legend_sizes_mm), so the box and its columns fit them. A sheet whose only theme is a classified raster then gets a filled legend instead of an empty box.- Existing layouts: a classified raster that was silently left out now appears. A saved layout that wants it out uses
exclude.
Who gains
- Users: any map of classes (land cover, soils, geology, slope classes, a supervised classification) gets its key on the sheet.
- Plugins: they can drop the polygonised copy they make only for the legend.
Metadata
Metadata
Assignees
Labels
No labels
Activity
fix(layout): the colorbar goes to the top raster with a colour scale;…
fix(layout): rasters a legend can't key are said once, with a count, …
fix(layout): a colorbar with no layer skips classed rasters; classes …
fix(layout): an empty colorbar, hidden groups, masks and samples in r…
fix(layout): an empty colorbar tells a colour table nothing keys, and…
fix(layout): the empty colorbar's notice doesn't claim a legend is on…
fix(raster): a colour table lists no negative value, as the map draws…
fix(layout): the colorbar's Layer picker and docs name its new default (
fix(layout): name the colorbar's default exactly: not drawn by classes (
docs(layout): the legend lists a masked colour table the pane doesn't…
test(layout): the sampled-classes notice from layout.publication and …
fix(layout): no sample or overview notice when the mask hides every p…
fix(layout): a raster still reading on top keeps the publication's co…
fix(raster): a colour table lists no fully transparent entry (opengeo…
feat(layout): a legend lists a classified raster's classes, as the La…