Skip to content
Permalink
Browse files

Revert "[processing] throw error if no layers selected in raster calc…

…ulator"

This reverts commit c09c301.
  • Loading branch information
alexbruy committed Feb 8, 2018
1 parent b6ff401 commit fcb50a68571a3bb69fc92a18d718e1fcf71fdfb6
Showing with 8 additions and 9 deletions.
  1. +8 −9 python/plugins/processing/algs/qgis/RasterCalculator.py
@@ -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()
@@ -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)

2 comments on commit fcb50a6

@nirvn

This comment has been minimized.

Copy link
Contributor

@nirvn nirvn replied Feb 8, 2018

@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

This comment has been minimized.

Copy link
Contributor

@nirvn nirvn replied Feb 8, 2018

@alexbruy I'm working on a fix.

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