Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r.reclass.area: Add flag to optionally output NULL raster if no areas are left after reclass #1728

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

griembauer
Copy link
Contributor

Currently, r.reclass.area with method=reclass fails if no areas greater or less than the specified value are found. This PR adds a flag to create a NULL-raster as output instead for this case.

@neteler
Copy link
Member

neteler commented Nov 30, 2021

(re-run black)

@neteler neteler closed this Nov 30, 2021
@neteler neteler reopened this Nov 30, 2021
@neteler
Copy link
Member

neteler commented Nov 30, 2021

@griembauer please see the black formatting error... thanks

@neteler neteler added bug Something isn't working raster Related to raster data processing labels Dec 9, 2021
@neteler neteler added this to the 8.0.1 milestone Dec 9, 2021
@wenzeslaus wenzeslaus modified the milestones: 8.0.1, 8.0.2 Feb 23, 2022
Comment on lines +175 to +177
op_str = "less"
else:
op_str = "greater"
Copy link
Member

Choose a reason for hiding this comment

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

The original code is right. Sentences cannot be build from parts because that makes translations impossible. If really needed, you could create two sentences and then put them together using another, possibly translatable, string.

_("No areas of size greater than or equal to %f " "hectares found.")
% limit
_("No areas of size %s than or equal to %f " "hectares found.")
% (op_str, limit)
Copy link
Member

Choose a reason for hiding this comment

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

To improve the code overall, please use .format() when rewriting the messages.

Comment on lines +186 to +187
expression = "$outfile = null()"
del mapcalc_kwargs["recfile"]
Copy link
Member

Choose a reason for hiding this comment

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

Maybe having two calls of mapcalc would result in a simpler code.

else:
op_str = "greater"
if nodata is True:
grass.warning(
Copy link
Member

Choose a reason for hiding this comment

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

You are probably in the best position to decide that, but if user requests NULL raster in those cases, is warning needed? Isn't that a verbose message instead? In other words, the new flag seems to make the the "no areas" state to be a standard state with appropriate output, so why a warning?

grass.run_command(
"g.remove", flags="f", type="vector", name=mapp, quiet=True
)
if grass.find_file(name=mapp, element="vector")["file"]:
Copy link
Member

Choose a reason for hiding this comment

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

Please comment on why you are making this change in the PR description.

@wenzeslaus wenzeslaus modified the milestones: 8.0.2, 8.4.0 Mar 16, 2022
@wenzeslaus
Copy link
Member

The code here needs some changes, but otherwise it is a very good improvement. I'm keeping it open, just moving the milestone.

@wenzeslaus wenzeslaus modified the milestones: 8.3.0, 8.4.0 Feb 10, 2023
@github-actions github-actions bot added Python Related code is in Python HTML Related code is in HTML module docs labels Mar 25, 2024
@wenzeslaus wenzeslaus modified the milestones: 8.4.0, Future Apr 27, 2024
@echoix echoix added the conflicts/needs rebase Rebase to or merge with the latest base branch is needed label Dec 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working conflicts/needs rebase Rebase to or merge with the latest base branch is needed docs HTML Related code is in HTML module Python Related code is in Python raster Related to raster data processing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants