The original SAGA IDW method does have a parameter for minimum number of points. But this parameter is not used in the QGIS version of the SAGA method.
As an alternative you could create a layer that contains only the points that have the minimum number of points within the search radius. Have a look at this answer for the code to make such a selection.
I hope this helps.
and here's hoping that Necromancer badge comes my way. ;-)
Here's how to use idw
to predict at some locations.
Use only these two packages:
> library(sp)
> library(gstat)
Make a test data set of 20 points with 20 N values that are the measurement we are interested in:
> d = data.frame(x=runif(20), y=runif(20), N=rnorm(20))
> coordinates(d)=~x+y
Let's set 3 of our measurements to NA
because these are missing - we want to fill these locations in:
> d$N[c(5,6,7)]=NA
Now run idw
with our valid data as locations
and our prediction locations as newdata
. Note how we use valid
as a true/false index to subset our data:
> valid = !is.na(d$N)
> predictions = idw(N~1,
locations=d[valid,,drop=FALSE],
newdata=d[!valid,,drop=FALSE])
Giving:
> predictions
coordinates var1.pred var1.var
5 (0.876017, 0.07675017) 0.3292105 NA
6 (0.3606106, 0.3929375) -0.8818549 NA
7 (0.8988331, 0.8903288) 0.1999656 NA
Note the prediction variance is NA
because the idw
method has no uncertainty measure. You will get different answers because I've used random numbers.
To put those prediction values back into the original data frame:
> d$N[!valid] = predictions$var1.pred
To get this to work on your data you will still have to convert the projection, but you only have to do this once - I really don't understand why you have a doubly-nested loop in your code. One call to idw
will predict at any number of newdata
locations given a set of valid location
data with coordinates and measurements.
Best Answer
The bulls eye effect describes concentric areas of the same value around known data points. It's simply an unfortunate artifact of IDW interpolation. The effect gets worse the more isolated your data points are.
IDW suffers from this problem more than other interpolation methods (e.g., Kriging), but to a large extent nearly any interpolation method will give unreliable results if the points are sparse and clustered. Conversely, you'll get good results with a range of methods if your points are dense and uniformly spaced.