Skip to content

Layout legend: list a classified raster's classes, as the Layers pane does #1679

Closed

Description

@elpidioassinaturas

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:

  1. Clip MapBiomas 2024 to Viçosa (MG). The result is a UInt8 raster with the file's colour table, Colormap renderer, 11 classes.
  2. Run layout.publication.
  3. 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

  1. 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.
  2. 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.
  3. Which classes: with allClasses: false (the default), the classes in the raster's statistics (stats.categories), without the values its mask hides. With allClasses: 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.
  4. Order: the renderer's order (the colour table's values, ascending, or the Unique Values classes as listed).
  5. exclude and hideOther: they work by layer name as they do for vector layers.
  6. 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.
  7. 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions