From 63524b16e71e132a065a888fc381e80e1af1e625 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Wed, 8 Jan 2025 13:02:30 +0100 Subject: [PATCH] fix postgresraster provider in grass algorithm r.in.gdal --- .../plugins/grassprovider/grass_algorithm.py | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/python/plugins/grassprovider/grass_algorithm.py b/python/plugins/grassprovider/grass_algorithm.py index 1f2eb3aec09d..d0743b51ebfd 100644 --- a/python/plugins/grassprovider/grass_algorithm.py +++ b/python/plugins/grassprovider/grass_algorithm.py @@ -923,9 +923,35 @@ def loadRasterLayer( if not destName: destName = f"rast_{os.path.basename(getTempFilename(context=context))}" self.exportedLayers[name] = destName + + if layer.providerType() == "postgresraster": + source = "" + uri = layer.dataProvider().uri() + source = f"PG: {uri.connectionInfo()}" + schema = uri.schema() + if schema: + source += f" schema='{schema}'" + table = uri.table() + source += f" table='{table}'" + column = uri.param("column") or uri.geometryColumn() + if column: + source += f" column='{column}'" + is_tiled = any( + [ + layer.dataProvider().xSize() != layer.dataProvider().xBlockSize(), + layer.dataProvider().ySize() != layer.dataProvider().yBlockSize(), + ] + ) + source += f" mode={2 if is_tiled else 1}" + where = layer.dataProvider().subsetString() + if where: + source += f" where='{where}'" + else: + source = os.path.normpath(layer.source()) + command = '{} input="{}" {}output="{}" --overwrite -o'.format( "r.external" if external else "r.in.gdal", - os.path.normpath(layer.source()), + source, f"band={band} " if band else "", destName, )