[GRASS-dev] Problems using pygrass' Region()

I am trying to repeatedly change the region in a script. To get the current region I would normally use

reg1 = grass.script.region()

When using pygrass, I can also use

import grass.pygrass.gis.region as region

reg2 = region.Region()

The first time I run this reg1 = reg2

Now, when I change the region, and run again:

reg3 = grass.script.region()

The reg3 values reflect the new region settings. However, when I run

reg2 = region.Region()

The reg4 values are the same as reg2

How do I get a Region object with the current / changed region settings?

Dear Paulo,

as explained by Vaclav:

"If you change region in C or using ctypes in Python, it is affecting
only the current process." [0].

Therefore the pygrass Region, that it is using C through ctypes, it is
working only on the current process.

"On the hand, if you change region using g.region, only region for
subprocesses is changed but library functions are not affected. So, g.region
will affect pygrass.modules.Module but not pygrass.raster, pygrass.vector
and others." [1]

I hope this make the things clearer.

Best regards

Pietro

[0] https://lists.osgeo.org/pipermail/grass-dev/2014-February/067543.html
[1] https://lists.osgeo.org/pipermail/grass-dev/2014-July/070200.html

Hi Pietro, thanks for the explanation

···

On Tue, Feb 17, 2015 at 7:38 AM, Pietro <peter.zamb@gmail.com> wrote:

Dear Paulo,

as explained by Vaclav:

“If you change region in C or using ctypes in Python, it is affecting
only the current process.” [0].

Therefore the pygrass Region, that it is using C through ctypes, it is
working only on the current process.

“On the hand, if you change region using g.region, only region for
subprocesses is changed but library functions are not affected. So, g.region
will affect pygrass.modules.Module but not pygrass.raster, pygrass.vector
and others.” [1]

I hope this make the things clearer.

Best regards

Pietro

[0] https://lists.osgeo.org/pipermail/grass-dev/2014-February/067543.html
[1] https://lists.osgeo.org/pipermail/grass-dev/2014-July/070200.html