Skip to content

Commit

Permalink
[processing] throw error if no layers selected in raster calculator
Browse files Browse the repository at this point in the history
algorithm (refs #17920)
  • Loading branch information
alexbruy committed Jan 23, 2018
1 parent d7e1813 commit c09c301
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions python/plugins/processing/algs/qgis/RasterCalculator.py
Expand Up @@ -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()
Expand All @@ -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)
Expand Down

2 comments on commit c09c301

@nirvn
Copy link
Contributor

@nirvn nirvn commented on c09c301 Feb 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@alexbruy
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.