# Calculating correlation between points and raster values with missing points (need missing as 0s) (QGIS)

I feel like this should be easy but I'm struggling. I have a raster data set of Topographic Wetness Index (TWI) and a point data set of crop yield. I want to see how TWI and yield are correlated by point sampling the raster, but I have holes of missing yield monitor data because the field flooded and the crops died in these spots. So, these missing areas are important and should be filled as zeroes, and not interpolated from surrounding point data. Here are some screenshots using QGIS to give a better view of the problem.

My yield monitor data with missing areas from flooding.

My topographic wetness index.

And the yield overlaid on TWI.

How should I fill these missing areas with zeroes so I can point sample and calculate correlation?

you have several ways to calculate the correlation between a raster and points, or between two aligned rasters.

You can use Grass or SAGA tools, or do it by programming.

Areas with no yield value should not be a problem, since the correlation is done with point-to-pixel matching. I recommend SAGA, it is very easy, direct and you can evaluate several adjustment equations.

Procedure:

SAGA is installed together with QGIS, run it.

In the data tab you will see both the raster and the point layer. Select the Raster (TWI in your case) and right click, in the drop down menu select scatterplot.

In the options, in `compare with...` change to points. At the bottom, in `points` select the layer of points and finally in `attributes` the field with the yield value. Click `Ok`

It shows you a result like the one in the image, the graph, the r2 value and the adjustment equation

At the top you can see some buttons, the first one allows you to alter the properties, including the adjustment equation. Remember, you can have a different fit than linear, for example exponential, logarithmic.

The second is to update if any of the layers have changed.

The THIRD converts the graph to a table, note in the image as it shows only the points from which I extracted the pixel values, I can take this table to a spreadsheet.

• Thank you! This was extremely helpful. I had trouble getting the extents to match after clipping, and ended up rasterizing the point data which then let me fill gaps with 0s, too. Worked like a charm otherwise!! Sep 16 '20 at 16:51