From 5357de3367f0f67762ca9c71d529b6bf7844f7c9 Mon Sep 17 00:00:00 2001 From: Anna Petrasova Date: Tue, 6 Jun 2023 09:32:30 +0200 Subject: [PATCH] wxGUI/query: set region matching the raster for each raster queried (#2992) --- gui/wxpython/mapdisp/frame.py | 26 +++++----------------- gui/wxpython/mapswipe/frame.py | 40 +++++++++++++--------------------- 2 files changed, 21 insertions(+), 45 deletions(-) diff --git a/gui/wxpython/mapdisp/frame.py b/gui/wxpython/mapdisp/frame.py index a1e0e9d4cad..bcb59f74994 100644 --- a/gui/wxpython/mapdisp/frame.py +++ b/gui/wxpython/mapdisp/frame.py @@ -1108,14 +1108,14 @@ def QueryMap(self, east, north, qdist, rast, vect): mapdisp=self._giface.GetMapDisplay(), giface=self._giface ) - # use display region settings instead of computation region settings - self.tmpreg = os.getenv("GRASS_REGION") - os.environ["GRASS_REGION"] = self.Map.SetRegion(windres=False) - rastQuery = [] vectQuery = [] - if rast: - rastQuery = grass.raster_what(map=rast, coord=(east, north), localized=True) + env = os.environ.copy() + for raster in rast: + env["GRASS_REGION"] = grass.region_env(raster=raster) + rastQuery += grass.raster_what( + map=raster, coord=(east, north), localized=True, env=env + ) if vect: encoding = UserSettings.Get(group="atm", key="encoding", subkey="value") try: @@ -1134,7 +1134,6 @@ def QueryMap(self, east, north, qdist, rast, vect): "Check database settings and topology." ).format(maps=",".join(vect)), ) - self._QueryMapDone() self._highlighter_layer.Clear() if vectQuery and "Category" in vectQuery[0]: @@ -1180,19 +1179,6 @@ def _queryHighlight(self, vectQuery): self._highlighter_layer.SetCats(tmp) self._highlighter_layer.DrawSelected() - def _QueryMapDone(self): - """Restore settings after querying (restore GRASS_REGION)""" - if hasattr(self, "tmpreg"): - if self.tmpreg: - os.environ["GRASS_REGION"] = self.tmpreg - elif "GRASS_REGION" in os.environ: - del os.environ["GRASS_REGION"] - elif "GRASS_REGION" in os.environ: - del os.environ["GRASS_REGION"] - - if hasattr(self, "tmpreg"): - del self.tmpreg - def OnQuery(self, event): """Query tools menu""" self.MapWindow.mouse["use"] = "query" diff --git a/gui/wxpython/mapswipe/frame.py b/gui/wxpython/mapswipe/frame.py index 653936e26dd..46ceedfefc2 100644 --- a/gui/wxpython/mapswipe/frame.py +++ b/gui/wxpython/mapswipe/frame.py @@ -752,30 +752,33 @@ def Query(self, x, y): east, north = self.GetFirstWindow().Pixel2Cell((x, y)) - # use display region settings instead of computation region settings - self.tmpreg = os.getenv("GRASS_REGION") - os.environ["GRASS_REGION"] = self.GetFirstMap().SetRegion(windres=False) - result = [] + env = os.environ.copy() if rasters[0]: - result.extend( - grass.raster_what(map=rasters[0], coord=(east, north), localized=True) - ) + for raster in rasters[0]: + env["GRASS_REGION"] = grass.region_env(raster=raster) + result.extend( + grass.raster_what( + map=raster, coord=(east, north), localized=True, env=env + ) + ) if vectors[0]: result.extend( grass.vector_what(map=vectors[0], coord=(east, north), distance=qdist) ) if rasters[1]: - result.extend( - grass.raster_what(map=rasters[1], coord=(east, north), localized=True) - ) + for raster in rasters[1]: + env["GRASS_REGION"] = grass.region_env(raster=raster) + result.extend( + grass.raster_what( + map=raster, coord=(east, north), localized=True, env=env + ) + ) if vectors[1]: result.extend( grass.vector_what(map=vectors[1], coord=(east, north), distance=qdist) ) - self._QueryMapDone() - result = PrepareQueryResults(coordinates=(east, north), result=result) if self._queryDialog: self._queryDialog.Raise() @@ -792,19 +795,6 @@ def _oncloseQueryDialog(self, event): self._queryDialog = None event.Skip() - def _QueryMapDone(self): - """Restore settings after querying (restore GRASS_REGION)""" - if hasattr(self, "tmpreg"): - if self.tmpreg: - os.environ["GRASS_REGION"] = self.tmpreg - elif "GRASS_REGION" in os.environ: - del os.environ["GRASS_REGION"] - elif "GRASS_REGION" in os.environ: - del os.environ["GRASS_REGION"] - - if hasattr(self, "tmpreg"): - del self.tmpreg - def GetMapToolbar(self): """Returns toolbar with zooming tools""" return self.toolbars["swipeMap"]