Skip to content

Commit

Permalink
Revert "[processing] throw error if no layers selected in raster calc…
Browse files Browse the repository at this point in the history
…ulator"

This reverts commit c09c301.
  • Loading branch information
alexbruy committed Feb 8, 2018
1 parent b6ff401 commit fcb50a6
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions python/plugins/processing/algs/qgis/RasterCalculator.py
Expand Up @@ -118,12 +118,9 @@ 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 = {}
layersDict = {os.path.basename(lyr.source().split(".")[0]): lyr for lyr in layers}
if 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 @@ -145,13 +142,15 @@ def processAlgorithm(self, parameters, context, feedback):
bbox = QgsProcessingUtils.combineLayerExtents(layers)

if bbox.isNull():
bbox = list(layersDict.values())[0].extent()
for lyr in layersDict.values():
bbox.combineExtentWith(lyr.extent())
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"))

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 fcb50a6

@nirvn
Copy link
Contributor

@nirvn nirvn commented on fcb50a6 Feb 8, 2018

Choose a reason for hiding this comment

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

@alexbruy , thanks.

I think we should dissociate the expression widget layers list from the layers QgsProcessingParameterMultipleLayers parameter.

Right now, if the raster layer alg is resurrected as is, it means that we do not have control over picking extent from a single layer or multiple layers.

@nirvn
Copy link
Contributor

@nirvn nirvn commented on fcb50a6 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 working on a fix.

Please sign in to comment.