Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wxGUI/query: set region matching the raster for each raster queried #2992

Merged
merged 1 commit into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 6 additions & 20 deletions gui/wxpython/mapdisp/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1074,14 +1074,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 @@ -1100,7 +1100,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 @@ -1146,19 +1145,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