1

I would like to create a virtual layer that creates polygons and make some raster zonal statistics in the geometry of these polygons. The aim is to use the polygons geometry to analyze pixel values of the raster band 1 value.

The original layer polygon is named source_polygons The raster that should be analyzed is named source_raster

The virtual layer should create polygons from source_polygons and add some rows:

  1. min : the minimum pixel value inside the geometry of source_polygons from source_raster band 1
  2. max : the maximal pixel value inside the geometry of source_polygons from source_raster band 1
  3. average : the average of pixel values inside the geometry of source_polygons from source_raster band 1

EDIT: I first tried to use virtual field, in order to do raster statistic into my polygons geometry, but I only found 2 options:

  • raster_value : which retrieve 1 value for 1 point (and my need a to retrieve values of several pixels into a polygon)
  • raster_statistic : which perfom statistic for the whole raster, and doesn't matter of the geometry of my polygons : it results the same result value in fields of my entities.

I wonder if it possible to perform raster zonal analyze using virtual layer?

3
  • There is no function for raster calculation available in Virtual Layer, check this topic gis.stackexchange.com/q/382795/99589
    – Taras
    Jul 20, 2023 at 15:56
  • @Taras : do you think it is possible to create custom function in order to access to raster calculation in Virtual layer ? this is what I understand from the link you shared, but I'm not sure.
    – zlikotp
    Jul 20, 2023 at 16:06
  • Can you share a sample of your data for testing purposes?
    – Taras
    Jul 21, 2023 at 17:55

1 Answer 1

2

The only way I can see of doing this, is by running the Zonal Statistics tool in QGIS. It will create a Virtual Layer for you, if you don’t specify an output.

  1. For the Input Layer, click on the 3 dots and select Select File, then navigate to your Vector layer and add it.
  2. Set your Raster as the Raster Layer
  3. In the Statistics to calculate click on the 3 dots and set to your required values.
  4. Click Run

As you will be requiring the "Average" Value might I suggest you set the Stat values to

  • Maximum
  • Minimum
  • Count
  • Sum

You can then use the Count and Sum values to calculate your Average. Although, you will have to manually create the Average column yourself.

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.