# [STATSGRASS] IDW when d=0?

Roger Bivand Roger.Bivand at nhh.no
Thu Dec 4 03:30:00 EST 2003

On Thu, 4 Dec 2003, Hamish wrote:

> Hi,
>
> Using an Inverse Distance Weighting formula, such as this one ..
>
> http://gis.nrcan.gc.ca/~viljoen/gis/interp/idw.ht1.jpg
>
> .. what happens when d=0? You want weighting to be huge when you are
> right on top of the interpolation spot, but not DIV0!
>
> I can change all 0's to 1's as my distances extend to 1000, but that's
> just a cheap hack and doesn't solve the general case.

Burrough & McDonnell (1998, p. 117) say: "Because in equation 5.16, f(d)
-> Inf as d -> 0, the value for an interpolation point that coincides with
a data point must be simply copied over." (Eq. 5.16 is:

\hat{z}(x_0) = \frac{\sum_{i=1}^n z(x_i) d_{i0}^{-r}} {\sum_{i=1}^n d_{i0}^{-r}}

where close-to-zero d_{i0}^{-r] becomes Inf, and so the sums blow up)

So a test would be: if d_{i0} < tol, then copy z(x_i) to z(x_0), and
forget all the other points.

I can't see any such test for small d_{i0} in sites/s.surf.idw/cmd/main.c
(5.0.3 release) - is that what you were wondering?

Sorry, too quick (l. 205):

if(dist = list[n].dist)

tests zero, then z(i) is copied through, but I think the test is fragile,
wouldn't it be better to test against machine precision?

It also seems to set r to 2 without saying, and I don't know that it
checks to make sure that we are on the plane (I can't see a trap for
non-projected locations).

Roger

>
>
>
> thanks for any ideas,
> Hamish
>
> _______________________________________________
> statsgrass mailing list
> statsgrass at grass.itc.it
> http://grass.itc.it/mailman/listinfo/statsgrass
>

--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of