[QGIS-Developer] core.QgsProcessingException: An error occurred while performing the calculation

Catania, Luke A ERDC-RDE-GRL-VA CIV Luke.A.Catania at erdc.dren.mil
Thu May 25 20:17:58 PDT 2023


I am trying to run a rastercalculator through a call to its python method and I get the error message core.QgsProcessingException: An error occurred while performing the calculation.  Not a very intuitive message.

The variable _cutfill_nodata_file used in the code below is a path to a result from a previous geoprocessing call and the file does exist, but the call to rastercalculator  seems to have an issue with that file.  If I replace _cutfill_nodata_file with self._elevation_layer.dataProvider().dataSourceUri()}@1 it works.  Not what I want to do, but just wanted to test nothing odd about my expression.  Do that basically adds the same layer to itself so I am doubling the cell values.  I want to add the values in the file _cutfill_nodata_file, but when I use that file, I get the error below. I tried using just the layer name and band which is what is used in the GUI raster calculator, but that does not work and I expect it to not as I think it only works if the layers are in the layer panel which they are not, they are in a temp folder, so I am calling the method using the file names.

elevation_30m_cutfill_file = os.path.join(self._temp_dir.name, f"{self._elevation_layer.name()}_{self.cutfill_layer.name()}.tif")
elevation_30m_cutfill_name = os.path.splitext(os.path.basename(elevation_30m_cutfill_file))[0]
expression = f'\"{self._elevation_layer.dataProvider().dataSourceUri()}@1\" + \"{_cutfill_nodata_file}@1\"'
processing.run(
            "qgis:rastercalculator",
            {
                'EXPRESSION':expression,
                'LAYERS':[self._elevation_layer.dataProvider().dataSourceUri()],
                'CELLSIZE':0,
                'EXTENT':None,
                'CRS':None,
                'OUTPUT':elevation_30m_cutfill_file
            }
        )

  File "C:\Users\RDTECLAC\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\site_selection\tools\cutfill\cutfill_dialog.py", line 745, in _calculate_cutfill_elevation_layer
              processing.run(
              File "C:\PROGRA~1/QGIS31~1.16/apps/qgis-ltr/./python/plugins\processing\tools\general.py", line 108, in run
              return Processing.runAlgorithm(algOrName, parameters, onFinish, feedback, context)
              File "C:\PROGRA~1/QGIS31~1.16/apps/qgis-ltr/./python/plugins\processing\core\Processing.py", line 174, in runAlgorithm
              ret, results = execute(alg, parameters, context, feedback, catch_exceptions=False)
              File "C:\PROGRA~1/QGIS31~1.16/apps/qgis-ltr/./python/plugins\processing\gui\AlgorithmExecutor.py", line 71, in execute
              results, ok = alg.run(parameters, context, feedback, {}, False)
             _core.QgsProcessingException: An error occurred while performing the calculation
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20230526/7706dd53/attachment.htm>


More information about the QGIS-Developer mailing list