grass.script: RegionManager/RegionManagerEnv: Add support for storing current region under a persistent name#7599
Conversation
|
Wouldn't region= work? |
5e6a868 to
db56e25
Compare
b65ab88 to
b503764
Compare
You are right @petrasovaa, this works normally. I intuitively expected an interface similar to MaskManager (so that there would be a region_name parameter, like mask_name), and then I didn’t see any example for region= in the docstring, so I didn’t realize that it’s already covered by **kwargs. I think we don’t necessarily need to add a region_name parameter to the API then, adding an example to the docstring should be enough. At the same time, I added a save method, which makes it possible to save the contextual region for later use (it’s basically what I originally implemented via region_name, but now I moved it into a method, which I think makes more sense overall). |
petrasovaa
left a comment
There was a problem hiding this comment.
It would be good if RegionManagerEnv has the same API.
This PR adds a new region_name parameter to RegionManager, enabling users to work with saved regions:
If region_name refers to an existing saved region and no additional g.region parameters are provided, the saved region is used directly without modification.
Example:
If region_name is provided together with additional g.region parameters, the region is saved under that name and persists after the context exits, allowing for reuse in future operations.
Example:
Existing usage without region_name remains the same as it was:
E.g.:
EDIT:
This PR introduces a new save() method that stores the current region under a persistent name, allowing it to be reused after the context exits. This method was added to the RegionManager and RegionManagerEnv classes. It also adds more docstring examples to clarify that saved regions were already supported through the standard g.region region= parameter.