Skip to content

r.category: preserve raster title when using rules=#7299

Open
HUN-sp wants to merge 3 commits intoOSGeo:mainfrom
HUN-sp:fix/r-category-preserves-title
Open

r.category: preserve raster title when using rules=#7299
HUN-sp wants to merge 3 commits intoOSGeo:mainfrom
HUN-sp:fix/r-category-preserves-title

Conversation

@HUN-sp
Copy link
Copy Markdown
Contributor

@HUN-sp HUN-sp commented Apr 8, 2026

Summary

Fixes #7199.

When rules= is used in r.category, the raster title gets overwritten because the category structure is initialized with an empty title. As a result, any previously set title is lost.

This change preserves the existing raster title while still replacing category labels based on the provided rules.

Testing

  • All existing tests pass
  • Verified manually by:
    • Setting a title using r.support
    • Running r.category rules=
    • Confirming the title remains unchanged using r.info

@github-actions github-actions bot added raster Related to raster data processing Python Related code is in Python C Related code is in C module tests Related to Test Suite general labels Apr 8, 2026
Comment thread scripts/g.extension/testsuite/test_addons_download.py Outdated
@HUN-sp
Copy link
Copy Markdown
Contributor Author

HUN-sp commented Apr 15, 2026

@petrasovaa Can u please review it ? All checks have passed

Copy link
Copy Markdown
Contributor

@petrasovaa petrasovaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have unrelated changes in your PR.

Comment thread raster/r.category/tests/r_category_test.py Outdated
HUN-sp added 2 commits April 15, 2026 23:51
Replace direct cats-file reading with r.info -e (JSON format) to
verify the preserved title. The cats file is an internal format;
using the public API is more robust and is consistent with how
other tests and tools read raster metadata.
@HUN-sp HUN-sp force-pushed the fix/r-category-preserves-title branch from cb6b985 to 93d2bbd Compare April 15, 2026 18:26
@HUN-sp
Copy link
Copy Markdown
Contributor Author

HUN-sp commented Apr 15, 2026

@petrasovaa Cleaned up the branch, the unrelated commits were fixes for CI failures that came up while working on this PR and should have been separate PRs. Test now uses r.info -e with JSON format as suggested.

Comment thread raster/r.category/main.c Outdated
Comment thread raster/r.category/main.c Outdated
Comment thread raster/r.category/tests/r_category_test.py Outdated
Comment thread raster/r.category/tests/r_category_test.py Outdated
- Remove extra braces around title-preservation block; move variable
  declarations to the top of the enclosing block
- Use Rast_get_cats_title() instead of accessing the struct field directly
- Use grass.tools Tools API in the test instead of grass.script
- Drop unnecessary -e flag from r.info call in the test
@HUN-sp HUN-sp force-pushed the fix/r-category-preserves-title branch from 803fa99 to 989f3ff Compare April 15, 2026 20:37
@HUN-sp
Copy link
Copy Markdown
Contributor Author

HUN-sp commented Apr 15, 2026

Addressed all four comments:

  • Removed extra braces; moved existing_cats and existing_title declarations to the top of the block
  • Switched to Rast_get_cats_title() instead of accessing the struct field directly
  • Test now uses the grass.tools Tools API
  • Dropped -e flag from r.info

@HUN-sp HUN-sp requested a review from petrasovaa April 16, 2026 01:29
@HUN-sp
Copy link
Copy Markdown
Contributor Author

HUN-sp commented Apr 16, 2026

@petrasovaa Hi , whenever u have time , please do review this.

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

Labels

C Related code is in C general module Python Related code is in Python raster Related to raster data processing tests Related to Test Suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] r.category removes map title

2 participants