Hello Muzaffer
I made a lot of changes/improvements to the IDW module a year or two ago
and so might be able to answer your questions.
Muzaffer Ayvaz wrote:
Hi;
I have some problems about the v.surf.idw.
First of all, I couldnt understand why the distances calculated without using sqrt. I mean;
list[i].dist = dy*dy + dx*dx
why this is not:
list[i].dist = sqrt(dy*dy+dx*dx) in the functions calculate_distances and
calculate_distances_noindex.
The weighted average is calculated inversely proportionally to the
square of the distance so this is correct (and also saves computation
time over finding a square root). If you wanted to change the
interpolation method to interpolate inversely proportionally to the
actual distance (or cube of the distance and so on) you could change
this section of the code (note there are about 4 places it would need to
be changed). But in general, textbooks seem to recommend using the
inverse square distance for interpolating most data.
The second problem and the last for now is that:
in main code;
nsearch = npoints < seacrh_points ? npoints : seacrh_points
and search_points is defined 12 globally. So, nseach can nat be bigger
than 12. But again in the functions calculate_distances and
calculate_distances_noindex there are two for loops:
one is ;
for(i=0;i<nsearch;i++){
..
}
the other;
/* go thru rest of the points now */
for(;i<npoints;i++){
..
}
What is the rest?? nsearch is either eq! ual to npoints or bigger than npoints.
The algorithm first has to search through all the points in the vector
map to find the 12 that are closest to the centre of the current raster
cell. Then it has to go through these 12 points and weight them by
distance to find the interpolated value.
If there are less than 12 points in the whole map then this first stage
(finding the 12 closest) doesn't need to be done and every point in the
map is used in the interpolation of every cell. So only the first for
loop is used in that case.
Not sure if that answers your question or not!
Paul