Skip to content

Commit

Permalink
Merge branch 'OSGeo:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
a0x8o authored May 14, 2024
2 parents 476c688 + 0ec833c commit 49930b8
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 29 deletions.
32 changes: 32 additions & 0 deletions gui/wxpython/gui_core/gselect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2414,6 +2414,17 @@ def getProjMatchCaption(projectionMatch):
)
data.append((layerId, raster, int(projectionMatch), grassName))
layerId += 1
elif self.dbWidgets["format"].GetStringSelection() == "Rasterlite":
rasters = self._getRasterliteDBRasters(dsn)
for raster in rasters:
grassName = GetValidLayerName(raster)
projectionMatch = hasRastSameProjAsLocation(dsn)
projectionMatchCaption = getProjMatchCaption(projectionMatch)
listData.append(
(layerId, raster, projectionMatchCaption, grassName)
)
data.append((layerId, raster, int(projectionMatch), grassName))
layerId += 1

# emit signal
self.reloadDataRequired.emit(listData=listData, data=data)
Expand Down Expand Up @@ -2696,6 +2707,27 @@ def _getPGDBRasters(self, dsn):
Debug.msg(3, f"GdalSelect._getPGDBRasters(): return {rasters}")
return rasters

def _getRasterliteDBRasters(self, dsn):
"""Get Rasterlite DB rasters

:param str dsn: Rasterlite DB data source name

:return list: list of Rasterlite DB rasters
"""
try:
from osgeo import gdal
except ImportError:
GError(
parent=self,
message=_("The Python GDAL package is missing. Please install it."),
)
return []
rasterlite = gdal.Open(dsn)
rasters = rasterlite.GetSubDatasets()
if rasters:
return [r[0].rsplit("table=")[-1] for r in rasters]
return [os.path.basename(rasterlite.GetFileList()[0]).rsplit(".")[0]]


class ProjSelect(wx.ComboBox):
"""Widget for selecting input raster/vector map used by
Expand Down
125 changes: 112 additions & 13 deletions gui/wxpython/history/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

from gui_core.wrap import SearchCtrl, StaticText, StaticBox, Button
from history.tree import HistoryBrowserTree
from icons.icon import MetaIcon

import grass.script as gs

from grass.grassdb import history

Expand Down Expand Up @@ -76,6 +79,10 @@ def __init__(self, parent, giface, title=("Command Info"), style=wx.TAB_TRAVERSA
self.giface = giface
self.title = title

self.region_settings = None

self._initImages()

self._createGeneralInfoBox()
self._createRegionSettingsBox()

Expand All @@ -97,6 +104,13 @@ def _layout(self):

self.Layout()

def _initImages(self):
bmpsize = (16, 16)
self.icons = {
"check": MetaIcon(img="success").GetBitmap(bmpsize),
"cross": MetaIcon(img="cross").GetBitmap(bmpsize),
}

def _createGeneralInfoBox(self):
"""Create static box for general info about the command"""
self.general_info_box = StaticBox(
Expand All @@ -119,20 +133,34 @@ def _createGeneralInfoBox(self):
def _createRegionSettingsBox(self):
"""Create a static box for displaying region settings of the command"""
self.region_settings_box = StaticBox(
parent=self, id=wx.ID_ANY, label=_("Region settings")
parent=self,
id=wx.ID_ANY,
label=_("Computational region during command execution"),
)
self.region_settings_box_sizer = wx.StaticBoxSizer(
self.region_settings_box, wx.VERTICAL
)

self.sizer_region_settings = wx.GridBagSizer(hgap=0, vgap=0)
self.sizer_region_settings.SetCols(2)
self.sizer_region_settings.SetRows(9)
self.sizer_region_settings_match = wx.BoxSizer(wx.HORIZONTAL)
self.region_settings_box_sizer.Add(
self.sizer_region_settings_match,
proportion=0,
flag=wx.ALL | wx.EXPAND,
border=5,
)

self.sizer_region_settings_grid = wx.GridBagSizer(hgap=0, vgap=0)
self.sizer_region_settings_grid.SetCols(2)
self.sizer_region_settings_grid.SetRows(9)

self.region_settings_box_sizer.Add(
self.sizer_region_settings, proportion=1, flag=wx.ALL | wx.EXPAND, border=5
self.sizer_region_settings_grid,
proportion=1,
flag=wx.ALL | wx.EXPAND,
border=5,
)
self.sizer_region_settings.AddGrowableCol(1)

self.sizer_region_settings_grid.AddGrowableCol(1)
self.region_settings_box.Hide()

def _general_info_filter(self, key, value):
Expand All @@ -142,7 +170,7 @@ def _general_info_filter(self, key, value):
)

def _region_settings_filter(self, key):
return (key != "projection") and (key != "zone")
return (key != "projection") and (key != "zone") and (key != "cells")

def _updateGeneralInfoBox(self, command_info):
"""Update a static box for displaying general info about the command"""
Expand Down Expand Up @@ -180,13 +208,13 @@ def _updateGeneralInfoBox(self, command_info):

def _updateRegionSettingsBox(self, command_info):
"""Update a static box for displaying region settings of the command"""
self.sizer_region_settings.Clear(True)
self.sizer_region_settings_grid.Clear(True)

region_settings = command_info["region"]
self.region_settings = command_info["region"]
idx = 0
for key, value in region_settings.items():
for key, value in self.region_settings.items():
if self._region_settings_filter(key):
self.sizer_region_settings.Add(
self.sizer_region_settings_grid.Add(
StaticText(
parent=self.region_settings_box,
id=wx.ID_ANY,
Expand All @@ -197,7 +225,7 @@ def _updateRegionSettingsBox(self, command_info):
border=5,
pos=(idx, 0),
)
self.sizer_region_settings.Add(
self.sizer_region_settings_grid.Add(
StaticText(
parent=self.region_settings_box,
id=wx.ID_ANY,
Expand All @@ -210,6 +238,58 @@ def _updateRegionSettingsBox(self, command_info):
)
idx += 1

self.sizer_region_settings_match.Clear(True)

# Region condition
history_region = self.region_settings
current_region = self._get_current_region()
region_matches = history_region == current_region

# Icon and button according to the condition
if region_matches:
icon = self.icons["check"]
button_label = None
else:
icon = self.icons["cross"]
button_label = _("Update current region")

# Static text
textRegionMatch = StaticText(
parent=self.region_settings_box,
id=wx.ID_ANY,
label=_("Region match"),
)
self.sizer_region_settings_match.Add(
textRegionMatch,
proportion=0,
flag=wx.ALIGN_CENTER_VERTICAL | wx.RIGHT,
border=10,
)

# Static bitmap for icon
iconRegionMatch = wx.StaticBitmap(self.region_settings_box, bitmap=icon)
self.sizer_region_settings_match.Add(
iconRegionMatch,
proportion=0,
flag=wx.ALIGN_CENTER_VERTICAL | wx.RIGHT,
border=10,
)

if button_label:
# Button for region update
buttonUpdateRegion = Button(self.region_settings_box, id=wx.ID_ANY)
buttonUpdateRegion.SetLabel(_("Update current region"))
buttonUpdateRegion.SetToolTip(
_("Set current computational region to the region of executed command")
)
buttonUpdateRegion.Bind(wx.EVT_BUTTON, self.OnUpdateRegion)
self.sizer_region_settings_match.Add(
buttonUpdateRegion,
proportion=1,
flag=wx.ALIGN_CENTER_VERTICAL,
border=10,
)

self.region_settings_box.Layout()
self.region_settings_box.Show()

Expand All @@ -226,11 +306,30 @@ def showCommandInfo(self, command_info):
def clearCommandInfo(self):
"""Clear command info."""
self.sizer_general_info.Clear(True)
self.sizer_region_settings.Clear(True)
self.sizer_region_settings_grid.Clear(True)
self.sizer_region_settings_text.Clear(True)
self._createGeneralInfoBox()
self._createRegionSettingsBox()
self._layout()

def _get_current_region(self):
"""Get current computational region settings."""
return gs.region()

def _get_history_region(self):
"""Get computational region settings of executed command."""
history_region = {}
for key, value in self.region_settings.items():
if self._region_settings_filter(key):
history_region[key] = value
return history_region

def OnUpdateRegion(self, event):
"""Set current region to the region of executed command."""
history_region = self._get_history_region()
gs.run_command("g.region", **history_region)
self.giface.updateMap.emit(render=False, renderVector=False)


class HistoryBrowser(wx.SplitterWindow):
"""History browser window for executing the commands from history log
Expand Down
16 changes: 16 additions & 0 deletions gui/wxpython/modules/import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,24 @@ def OnRun(self, event):
if self.dsnInput.GetType() == "dir":
idsn = os.path.join(dsn, layer)
elif self.dsnInput.GetType() == "db":
idsn = dsn
if "PG:" in dsn:
idsn = f"{dsn} table={layer}"
elif os.path.exists(idsn):
try:
from osgeo import gdal
except ImportError:
GError(
parent=self,
message=_(
"The Python GDAL package is missing."
" Please install it."
),
)
return
dataset = gdal.Open(dsn)
if "Rasterlite" in dataset.GetDriver().ShortName:
idsn = f"RASTERLITE:{dsn},table={layer}"
else:
idsn = dsn

Expand Down
11 changes: 1 addition & 10 deletions python/grass/grassdb/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

from datetime import datetime
import grass.script as gs
from grass.script.utils import parse_key_val


class Status(Enum):
Expand Down Expand Up @@ -274,15 +273,7 @@ def get_initial_command_info(env_run):
mask3d_present = (mapset_path / "grid3" / "RASTER3D_MASK").exists()

# Computational region settings
region_settings = dict(
parse_key_val(
gs.read_command("g.region", flags="g", env=env_run), val_type=float
)
)

# Convert floats to integers if possible
for key, value in region_settings.items():
region_settings[key] = int(value) if value.is_integer() else value
region_settings = gs.region(env=env_run)

# Finalize the command info dictionary
cmd_info = {
Expand Down
3 changes: 0 additions & 3 deletions python/grass/script/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,6 @@ def get_param(self, value, element="name", raiseError=True):
if isinstance(val, (list, tuple)):
if value in val:
return p
elif isinstance(val, (bytes, str)):
if p[element][: len(value)] == value:
return p
else:
if p[element] == value:
return p
Expand Down
11 changes: 11 additions & 0 deletions python/grass/script/tests/test_script_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from grass.script.task import grassTask as gtask


def test_mapcalc_simple_e_name():
gt = gtask("r.mapcalc.simple")
assert gt.get_param("e")["name"] == "e"


def test_mapcalc_simple_expession_name():
gt = gtask("r.mapcalc.simple")
assert gt.get_param("expression")["name"] == "expression"
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion raster/r.flow/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include <grass/glocale.h>
#include "r.flow.h"
#include "mem.h"
#include "io.h"
#include "flow_io.h"
#include "aspect.h"
#include "precomp.h"

Expand Down
2 changes: 1 addition & 1 deletion raster/r.flow/mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <grass/raster.h>
#include <grass/glocale.h>
#include "r.flow.h"
#include "io.h"
#include "flow_io.h"
#include "mem.h"

/************************** MEMORY MGMT/ACCESS **************************/
Expand Down
2 changes: 1 addition & 1 deletion raster/r.flow/precomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <grass/raster.h>
#include <grass/glocale.h>
#include "r.flow.h"
#include "io.h"
#include "flow_io.h"
#include "mem.h"
#include "aspect.h"

Expand Down

0 comments on commit 49930b8

Please sign in to comment.