Skip to content

Commit

Permalink
wxGUI/query: set region matching the raster for each raster queried (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
petrasovaa authored Jun 6, 2023
1 parent 0fa1549 commit b56634b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 45 deletions.
26 changes: 6 additions & 20 deletions gui/wxpython/mapdisp/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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]:
Expand Down Expand Up @@ -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"
Expand Down
40 changes: 15 additions & 25 deletions gui/wxpython/mapswipe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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"]
Expand Down

0 comments on commit b56634b

Please sign in to comment.