Repository navigation
feat(raster): label legend classes with the category names of the .aux.xml - #971
Conversation
…x.xml A classified raster's legend listed its values (1, 2, 3...) even when GDAL's .aux.xml sidecar names each class (<CategoryNames>, as written by SetCategoryNames). The sidecar reader now keeps those names on the band, and the Colormap and Unique Values legend rows use them, falling back to the value for a class without a name. Part of opengeos#889. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Parse PAM categories crates/data/src/raster/pam.rs |
PamBand exposes category names parsed from PAM XML. Parsing trims names, limits name length and list size, and removes trailing empty entries while preserving interior empty entries. |
Load categories into raster bands crates/data/src/raster/mod.rs |
Band stores class names and returns a name only for a valid, named index. apply_pam copies nonempty PAM category lists into bands. |
Use class names in legends crates/map/src/raster.rs, docs/user-guide/data.md |
Unique Values and Colormap legends use class names when available and formatted values otherwise. The raster guide describes this behavior. |
Priority:
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Feature
Sequence Diagram(s)
sequenceDiagram
participant PAM as PAM .aux.xml
participant Parser as PamBand parser
participant Raster as apply_pam
participant Legend as RasterLayer::legend
PAM->>Parser: provide CategoryNames
Parser->>Raster: return PamBand categories
Raster->>Legend: populate Band classes
Legend->>Legend: use class_name or formatted value
Possibly related issues
- opengeos/RustGIS#889: Requests raster legend class names, which this change reads from PAM sidecars and uses in legend entries.
Possibly related PRs
- opengeos/RustGIS#890: Extends the same PAM band metadata and sidecar-reading path used by this change.
Suggested reviewers: giswqs
Merge Risk: 
Minimal · up to 2aa2c
-
No confirmed issue prevents merging after normal checks.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Description check
-
Explanation
The description follows the required Summary, Testing, and Related issue sections. It explains the change, documents scope exclusions, lists new tests and verification steps, and links the work to issue
#889.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 3 files. (1 skipped: 1 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
A rabbit found names in the sidecar one day
And carried them neatly to legends on display
For unnamed classes, the numbers remain
While category labels hop into the frame
The raster now wears its names with delight
Comment @coderabbitai help to get the list of available commands.
Code reviewBugs: None found. I checked the Security: None found. Category names come from the sidecar, but they are plain text in egui, trimmed, cut to 256 characters, capped at 65,536 per band, and the sidecar itself is capped at 16 MiB. The new code adds no Performance: None significant. Lookups are O(1) via Quality (nits, confidence high unless noted):
AGENTS.md: Compliant. No I left no inline comments: the findings above are nits that don't justify separate threads. Change sizeCompared: the whole PR against main (merge base 9285e05 to PR head 2aa2c10).
|
📖 Docs preview
GitHub Pages takes a minute or two to publish a new commit. |
Summary
A classified raster with a colour table showed its values (1, 2, 3 …) in the Layers pane legend, even when GDAL's
.aux.xmlsidecar names each class. GDAL writes those names withSetCategoryNames, as<CategoryNames>in the band's<PAMRasterBand>.pam.rsreads<CategoryNames>: one name per value from 0, empty for a value without a name, trimmed and cut at 256 characters like descriptions, and at most 65,536 per band.Bandgainsclassesandclass_name(v).apply_pamfills them, next to the band's description.docs/user-guide/data.mdmentions the category names next to the other things the sidecar supplies.Not in this PR (the second part of #889 and related):
Class_Names/Valuecolumns);layer.classStylesetting labels on raster classes;ColorScale::Valueswith the values;read_converted), which don't read the sidecar today.Testing
rustgis-data,raster::pam::tests::reads_class_names: empty, unnamed and trailing categories, and the 256-character cut;rustgis-data,raster::tests::gdal_sidecars_name_classes: a GeoTIFF written and read back with its.aux.xml;rustgis-map,raster::tests::legend_labels_classes_with_their_names: Colormap and Unique Values labels, and the fallback to values.Related issue
Part of #889.
🤖 Generated with Claude Code
Summary by CodeRabbit