Skip to content
Permalink
Browse files

[processing] throw error if no layers selected in raster calculator

algorithm (refs #17920)
  • Loading branch information
alexbruy committed Jan 23, 2018
1 parent d7e1813 commit c09c3018035eb7a4f47acbde7f3dae405ba444db
Showing with 9 additions and 8 deletions.
  1. +9 −8 python/plugins/processing/algs/qgis/RasterCalculator.py
@@ -118,9 +118,12 @@ def displayName(self):
def processAlgorithm(self, parameters, context, feedback):
expression = self.parameterAsString(parameters, self.EXPRESSION, context)
layers = self.parameterAsLayerList(parameters, self.LAYERS, context)

if not layers:
raise QgsProcessingException(self.tr("No layers selected"))

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

for lyr in QgsProcessingUtils.compatibleRasterLayers(context.project()):
name = lyr.name()
@@ -142,15 +145,13 @@ def processAlgorithm(self, parameters, context, feedback):
bbox = QgsProcessingUtils.combineLayerExtents(layers)

if bbox.isNull():
if layersDict:
bbox = list(layersDict.values())[0].extent()
for lyr in layersDict.values():
bbox.combineExtentWith(lyr.extent())
else:
raise QgsProcessingException(self.tr("No layers selected"))
bbox = list(layersDict.values())[0].extent()
for lyr in layersDict.values():
bbox.combineExtentWith(lyr.extent())

def _cellsize(layer):
return (layer.extent().xMaximum() - layer.extent().xMinimum()) / layer.width()

cellsize = self.parameterAsDouble(parameters, self.CELLSIZE, context) or min([_cellsize(lyr) for lyr in layersDict.values()])
width = math.floor((bbox.xMaximum() - bbox.xMinimum()) / cellsize)
height = math.floor((bbox.yMaximum() - bbox.yMinimum()) / cellsize)

2 comments on commit c09c301

@nirvn

This comment has been minimized.

Copy link
Contributor

@nirvn nirvn replied Feb 8, 2018

@alexbruy , I'm pretty sure this caused the following regression: https://issues.qgis.org/issues/18060

@alexbruy

This comment has been minimized.

Copy link
Contributor Author

@alexbruy alexbruy replied Feb 8, 2018

@nirvn no, raster calculator was broken even before it. This just fixed one of the issues, reported in another tickets. Reverted now.

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