Skip to content

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

Merged
petrasovaa merged 7 commits into
OSGeo:mainfrom
HUN-sp:fix/r-category-preserves-title
Apr 23, 2026
Merged

petrasovaa merged 7 commits into
OSGeo:mainfrom
HUN-sp:fix/r-category-preserves-title

Conversation

@HUN-sp

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

Copy link
Copy Markdown
Contributor

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
@HUN-sp

HUN-sp commented Apr 15, 2026

Copy link
Copy Markdown
Contributor Author

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

@petrasovaa petrasovaa left a comment

Copy link
Copy Markdown
Contributor

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.

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

HUN-sp commented Apr 15, 2026

Copy link
Copy Markdown
Contributor Author

@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 Resolved
Comment thread raster/r.category/main.c Resolved
- 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

HUN-sp commented Apr 15, 2026

Copy link
Copy Markdown
Contributor Author

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

HUN-sp commented Apr 16, 2026

Copy link
Copy Markdown
Contributor Author

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

@HUN-sp

HUN-sp commented Apr 18, 2026

Copy link
Copy Markdown
Contributor Author

@petrasovaa Hi, any update on this ?

@HUN-sp
HUN-sp force-pushed the fix/r-category-preserves-title branch from 5fa045d to a5fb815 Compare April 21, 2026 11:46
@HUN-sp
HUN-sp requested a review from petrasovaa April 21, 2026 15:52
@petrasovaa
petrasovaa enabled auto-merge (squash) April 23, 2026 20:32
@petrasovaa
petrasovaa merged commit 37f5195 into OSGeo:main Apr 23, 2026
26 checks passed
@github-actions github-actions Bot added this to the 8.6.0 milestone Apr 23, 2026
@HUN-sp

HUN-sp commented Apr 24, 2026

Copy link
Copy Markdown
Contributor Author

Thank you @petrasovaa for the reviews and guidance on getting this merged .

@HUN-sp
HUN-sp deleted the fix/r-category-preserves-title branch April 24, 2026 03:00
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