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/gui_core: fix import Rasterlite DB raster #2513

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)
petrasovaa marked this conversation as resolved.
Show resolved Hide resolved
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 GDAL library is missing. Please install it."),
petrasovaa marked this conversation as resolved.
Show resolved Hide resolved
)
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
23 changes: 23 additions & 0 deletions gui/wxpython/modules/import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,31 @@ 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):
import subprocess

dataset_info = subprocess.run(
["gdalinfo", "-json", dsn],
capture_output=True,
)
if dataset_info.stderr:
GError(
parent=self,
message=grass.decode(dataset_info.stderr),
)
return
if dataset_info.stdout:
import json

dataset_info = json.loads(
grass.decode(dataset_info.stdout),
)
# Rasterlite DB
if "Rasterlite" in dataset_info["driverShortName"]:
petrasovaa marked this conversation as resolved.
Show resolved Hide resolved
idsn = f"RASTERLITE:{dsn},table={layer}"
else:
idsn = dsn

Expand Down