<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Nov 13, 2014 at 5:21 AM, <span dir="ltr"><<a href="mailto:svn_grass@osgeo.org" target="_blank">svn_grass@osgeo.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div id=":1uc" class="" style="overflow:hidden">+ grass.run_command('g.region', rast=origrast)<br>
+ grass.run_command('g.region', vect=tmp_vect)<br>
+ grass.run_command('g.region', align=origrast)</div></blockquote></div><br></div><div class="gmail_extra">I'm not sure in which context you are calling this but unless it is clear from the user interface that region will change and user expects that, you should read the following.<br></div><div class="gmail_extra"><br>If you are calling processes which needs different region, you must use `env` parameter and do region override just for subprocesses in order not to change the region of the whole GRASS session.<br><br></div><div class="gmail_extra">The API for temporary region which is in grass.script.core works just for scripts which change the environment for themselves and their subprocesses but not for rest of GRASS. However, if you use the API in GUI, you change the environment for the whole GUI (process) which is not what you want. This means that you need to keep "environment" dictionary in your class(es) and pass it to all subprocesses you call.<br><br></div><div class="gmail_extra">There is no API for this yet. Anna recently created a function which can be used for that.<br><br>def get_environment(tmp_regions, **kwargs):<br>"""Returns environment for running modules.<br><br>All modules for which region is important should<br>pass this environment into run_command or similar.<br><br></div><div class="gmail_extra">List of regions is used to keep track of created files<br>and should be used to remove these files later.<br></div><div class="gmail_extra"><br>:param tmp_regions: a list of temporary regions<br>:param kwargs: arguments for g.region<br>:return: environment as a dictionary<br>"""<br>name = str(uuid.uuid4())[:8]<br>gcore.run_command('g.region', flags='u', save=name, **kwargs)<br>tmp_regions.append(name)<br>env = os.environ.copy()<br>env['WIND_OVERRIDE'] = name<br>env['GRASS_VERBOSE'] = '0'<br>env['GRASS_MESSAGE_FORMAT'] = 'standard'<br>if 'GRASS_REGION' in env:<br>del env['GRASS_REGION']<br>return env<br><br><br></div></div>