In QGIS (3.28) one can choose Zonal statistics "Append to Layer" as an output option. I'd love to do that, to append zonal statistics columns "in place", however I am lost on how to use this option. Zonal statistics: Append to Layer

When selecting this option, it prompts you to select a file (via Browser). I'd already expect it to offer currently loaded layers for convenience, but browsing to the respective data source I can do. Obviously only datasets similarly shaped as the "Input Layer" make sense as an option (need same number of rows, ideally with a key). When selecting the (sensible) data source of my "Input Layer", I often get a Python error. It happened too for other datasets.

Messages log:
2023-08-15T19:56:34     WARNING    Python error : An error has occurred while executing Python code: See message log (Python Error) for more details.

Message log (Python Error):
2023-08-15T19:56:34     WARNING    Traceback (most recent call last):
              File "C:\OSGeo4W/apps/qgis-ltr/./python/plugins\processing\gui\ParametersPanel.py", line 233, in createProcessingParameters
              raise AlgorithmDialogBase.InvalidParameterValue(param, widget)
             processing.gui.AlgorithmDialogBase.AlgorithmDialogBase.InvalidParameterValue: (, )

If that for some unknown reason doesn't happen on some cases, I get to a dialog showing all fields of the dataset (Name, Type, Length, Precision, ...), but all greyed out, with only the option to write something into "Source Expression". If I then go back, the choosen dataset file is filled into the output line (as if I'd choosen "Save to File" to exactly that file). This also works on the "Input Layer"-File. However if running with these settings either

  1. nothing happens, the layer is unchanged, without any appended zonal statistics, or
  2. I get an error when executing, saying that he couldn't create layer ("OGR error: D:/my/path/stands.gpkg is not a directory"), even though he can perfectly process the same file/name as Input Layer...
    Error when choosing a file

Am I missing something? How is this supposed to work?

I'd gladly use other options, but the solution (Zonal Statistics (in place) opened via Graphical Modeler) doesn't seem to be applicable any more, and I'm hesistant to downgrade to QGIS 3.10 to do this (Append raster zonal statistics to layer in QGIS). Much like I'd love to be able to do Spatial join (multiple) layers "in place" with QGIS, I find this a very important issue that I don't have a solution for.


1 Answer 1


I've had the same issue as you exactly - have been struggling with this a lot with 8 new temporary geo packages created in the intermittent steps (I have version 3.32.1). The zonal stats in place doesn't come up in the modeler for me either and it appears very inefficient to do everything step-by-step.

The best solution (work-around) I came up that is still inefficient but streamlines the process a little bit especially if you have to do several rounds of zonal stats is to save the Python code equivalent for each file, you input and output as this additionally created geo-packages, but you can specify to only runAndLoadResults (i.e. add the layer to the map) to the last step, so that at least your project doesn't get too cluttered:

enter image description here

And then if you open the Python console, and then open the "Show Editor", then paste your multiple code lines in here, it'll run smoothly in the background to reduce the hands-on part of this process. Doesn't exactly allow to append to layer, but is the best option I came up with so far and wanted to share.

enter image description here

Then at the end, you can just once delete the temp?.gpkg files, which in this case would be stored in the same folder as the opened QGIS project folder (at least with my settings that's what happened).

  • cool, thank you for sharing.
    – Honeybear
    Commented Sep 7, 2023 at 9:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.