Skip to content

Commit

Permalink
wxGUI/gui_core: fix import Rasterlite DB raster (OSGeo#2513)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmszi authored May 13, 2024
1 parent 817af48 commit 9f7222b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 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 @@ -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)
Expand Down Expand Up @@ -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
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

0 comments on commit 9f7222b

Please sign in to comment.