Repository navigation
r.reclass.area: Implement -i flag to invert area size filter - #8098
Merged
petrasovaa merged 3 commits intoOct 27, 2026
Merged
Conversation
In `scripts/r.reclass.area/r.reclass.area.py`: - Wire up the `-i` flag in `main()` by passing `invert=flags["i"]` to `reclass()`. - In `reclass()`, invert the area threshold check when `invert=True` so clumps between `lower` and `upper` are removed instead of kept. - Add complete translatable messages for inverted filtering states. - Disallow `-i` with `method='rmarea'` and add `excludes: -m, -i` to parser rules. - Update documentation in `r.reclass.area.md` and `r.reclass.area.html`. - Add test cases in `test_r_reclass_area.py`. Fixes OSGeo#8097. Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
With -i, lower=20 and upper=4000, clumps larger than 4000 hectares are kept as well, so the minimum category is below 900. Use the same bounds as the non-inverted lower/upper test. Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
petrasovaa
requested changes
Oct 22, 2026
petrasovaa
left a comment
Contributor
There was a problem hiding this comment.
Thanks! There are couple small improvements still needed.
- Improve condition readability in `reclass()` with `keep` variable. - Document that `-i` is only supported with `method=reclass` and not with `method=rmarea`. - Update test suite: add `test_reclass_upper_invert` with distinct min/max range and assert that normal and inverted outputs in `test_reclass_lower_upper_invert` have zero overlapping non-null cells. Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
Contributor
Author
|
Thanks for the review @petrasovaa! I've updated everything based on your feedback:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR implements the
-i(invert) flag functionality inr.reclass.area:reclass(): passedinvertboolean flag and updated the inclusion logic:lowerandupperare filtered out when-iis set, preserving clumps smaller thanloweror greater thanupper.invert=True.% excludes: -m, -iin parser rules (since-mprunes small clumps during clumping prior to inversion) and raisedgs.fatal(_("Flag -i is not supported with method='rmarea'"))when combining-iwith vector-basedmethod='rmarea'.-ibehavior inr.reclass.area.mdandr.reclass.area.html.lower,lower+upper, and validation for unsupportedmethod='rmarea'.Motivation and context
Fixes #8097
The
-iflag was defined in the interface definition ofr.reclass.area.py(% flag: i,% description: Invert selection (remove areas within size range)), but was never passed toreclass()or evaluated, leaving it completely inoperative.How has this been tested?
ruff check scripts/r.reclass.area/andruff format --check scripts/r.reclass.area/(all passed cleanly).scripts/r.reclass.area/testsuite/test_r_reclass_area.py:test_reclass_lower_invert: checks that clumps below the lower threshold are retained.test_reclass_lower_upper_invert: checks that clumps outside the[lower, upper]range are retained.test_rmarea_invert_unsupported: verifies proper module failure when-iis passed withmethod=rmarea.Screenshots (if appropriate)
N/A
Types of changes
Checklist
Signed-off-by: bhuvan-somisetty somisettybhuvan5@gmail.com