Skip to content

r.category: preserving raster title#7210

Open
Vedant-Bachhav wants to merge 2 commits intoOSGeo:mainfrom
Vedant-Bachhav:fix-r-category-title
Open

r.category: preserving raster title#7210
Vedant-Bachhav wants to merge 2 commits intoOSGeo:mainfrom
Vedant-Bachhav:fix-r-category-title

Conversation

@Vedant-Bachhav
Copy link
Copy Markdown

Fixes #7199

I was able to reproduce the issue locally where the raster title set using r.support gets removed after running r.category.
in code categories were initialized with empty title and was overwritten by existing raster title, fixed this issue by reading the existing metadata before modifying it, thus preserving the raster title.

I tested the fix locally multiple times with many scenarios to ensure title remains unchanged after applying categories

@github-actions github-actions bot added raster Related to raster data processing C Related code is in C module labels Mar 22, 2026
@Vedant-Bachhav Vedant-Bachhav changed the title Fixed r.category removing raster title by preserving existing metadat… r.category removing raster title by preserving existing metadat… Mar 22, 2026
@Vedant-Bachhav Vedant-Bachhav changed the title r.category removing raster title by preserving existing metadat… r.category preserving raster title Mar 22, 2026
@Vedant-Bachhav Vedant-Bachhav changed the title r.category preserving raster title r.category: preserving raster title Mar 22, 2026
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@petrasovaa
Copy link
Copy Markdown
Contributor

Hm, do you need the init then? Did you look how would the old categories that are read in interact with the new one? Wouldn't the old ones possibly stay in there? What if the counts are different?

@Vedant-Bachhav
Copy link
Copy Markdown
Author

Hi @petrasovaa,

Thanks for pointing it out, it helped me clarify the issue.
I tried to reproduce the scenarios you mentioned and i observed:

  • Old categories are not fully cleared and remain after applying new rules
  • When the new rules define fewer categories, the remaining old entries still persist (count mismatch)
  • New categories partially overwrite existing ones instead of replacing them completely
  • Running the same rules multiple times still results in mixed output, indicating that categories are not properly reinitialized

So it seems old cats are read in are interacting with new ones and getting merged instead of replacing.

Regarding inti thing, it doesnt appear to fully clear prev read cats, If we avoid reading existings cats and start with clean structure we still need init to initializa the structure properly before applying new rules.

so coming to the fix,

  1. avoid reading existing cats when rules are provide and start with clean struct using "init_cats" before applying new rules
  2. alternatively if you think read is required we can explicitly clear them before reinitializing and applying new rules

the first one seems more cleaner, does this approach align with the intended behaviour, if yes i will proceed and implement and then update this PR.

@wenzeslaus
Copy link
Copy Markdown
Member

One way or another, this needs a set of tests covering r.category and r.support title functionality. The test should make clear what is happening with the title and when.

@Vedant-Bachhav
Copy link
Copy Markdown
Author

Hi @wenzeslaus ,

I worked on the tests by adding for the r.category,r.title functionality, in the tests env (simple dataset) everything works fine and cats are clearly replaced, so the issue is not reproduced there.

But when teste manually where existing cats are present, the old cats still remains and get mixed with new ones, so it seems to depends on existing metadata. I tried a fix and tested it manually and this time the cats were properly reinitialized before applying new rules, and it seems to resolve the issue !

Right now the behaviour is not been able to reproduce inside pytest, should i still try to simulate that behavior or can i push that fix which corrects the behavior?

@wenzeslaus
Copy link
Copy Markdown
Member

I don't want to merge the change without a test which parallels the encountered issue.

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 module raster Related to raster data processing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] r.category removes map title

3 participants