diff --git a/gui/wxpython/gui_core/gselect.py b/gui/wxpython/gui_core/gselect.py index 12773f1c449..de9a7d67636 100644 --- a/gui/wxpython/gui_core/gselect.py +++ b/gui/wxpython/gui_core/gselect.py @@ -2370,6 +2370,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) @@ -2652,6 +2663,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 diff --git a/gui/wxpython/modules/import_export.py b/gui/wxpython/modules/import_export.py index da082feb68d..df1882c6ed6 100644 --- a/gui/wxpython/modules/import_export.py +++ b/gui/wxpython/modules/import_export.py @@ -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