Skip to content
Browse files

[processing] make output crs optional in the raster calculator

  • Loading branch information
nirvn committed Feb 9, 2018
1 parent c4874b3 commit e27847d3832664ed987740569cc6241fddfc65c6
Showing with 17 additions and 5 deletions.
  1. +17 −5 python/plugins/processing/algs/qgis/
@@ -97,7 +97,7 @@ def evaluateForModeler(self, value, model):
self.addParameter(QgsProcessingParameterMultipleLayers(self.LAYERS,'Reference layer(s) (used for automated determination extent and cellsize)'),'Reference layer(s) (used for automated extent, cellsize, and CRS)'),
@@ -107,7 +107,7 @@ def evaluateForModeler(self, value, model):
self.addParameter(QgsProcessingParameterExtent(self.EXTENT,'Output extent'),
self.addParameter(QgsProcessingParameterCrs(self.CRS, 'Output CRS', 'ProjectCrs'))
self.addParameter(QgsProcessingParameterCrs(self.CRS, 'Output CRS', optional=True))

def name(self):
@@ -119,22 +119,34 @@ def displayName(self):
def processAlgorithm(self, parameters, context, feedback):
expression = self.parameterAsString(parameters, self.EXPRESSION, context)
layers = self.parameterAsLayerList(parameters, self.LAYERS, context)
crs = self.parameterAsCrs(parameters, self.CRS, context)

layersDict = {}
if layers:
layersDict = {os.path.basename(lyr.source().split(".")[0]): lyr for lyr in layers}

crs = self.parameterAsCrs(parameters, self.CRS, context)
if not layers and not crs.isValid():
raise QgsProcessingException("No reference layer selected nor CRS provided"))

if not crs.isValid() and layers:
crs = list(layersDict.values())[0].crs()

bbox = self.parameterAsExtent(parameters, self.EXTENT, context)
if not layers and bbox.isNull():
raise QgsProcessingException("No reference layer selected to automate extent box"))
raise QgsProcessingException("No reference layer selected nor extent box provided"))

if not bbox.isNull():
bboxCrs = self.parameterAsExtentCrs(parameters, self.EXTENT, context)
if bboxCrs != crs:
transform = QgsCoordinateTransform(bboxCrs, crs, context.project())
bbox = transform.transformBoundingBox(bbox)

if bbox.isNull() and layers:
bbox = QgsProcessingUtils.combineLayerExtents(layers, crs)

cellsize = self.parameterAsDouble(parameters, self.CELLSIZE, context)
if not layers and cellsize == 0:
raise QgsProcessingException("No reference layer selected to automate cellsize value"))
raise QgsProcessingException("No reference layer selected nor cellsize value provided"))

def _cellsize(layer):
ext = layer.extent()

0 comments on commit e27847d

Please sign in to comment.
You can’t perform that action at this time.