I have spatial data points with x-y-coordinates. They represent the banks of a channel. Now, I need to make this channel bank line to be denser. I want to linearly interpolate the bank points by giving a minimum distance in meters that all interpolated points must have to each other.
For example: the blue points are the original points. The red are the interpolated points. They are all at least 1 m apart from each other. The lower right two blue points do not receive an interpolation.
How can I achieve this?
EDIT
Downvoting questions seems to be SO new hobby. What can I do to make you guys happy? My efforts?
par = list()
par$bank.min.dist = 6 # meters
for(i in c(2:length(data$x[ix]))){
# add the actual point
banks$x[[bank]] = c(banks$x[[bank]], data$x[ix.l][i-1])
banks$y[[bank]] = c(banks$y[[bank]], data$y[ix.l][i-1])
# calculate distance between consecutive bank points
cb_dist = ( ( data$x[ix][i] - data$x[ix][i-1] )^2 + ( data$y[ix][i] - data$y[ix][i-1] )^2 ) ^(1/2)
# if distance larger than threshold distance interpolate
if(cb_dist > par$bank.min.dist){
# calculate number of artificial points
nr_of_pts = ceiling(cb_dist / par$bank.min.dist)
ap = ap + nr_of_pts
# add artificial points
for(ido in c(1: (nr_of_pts-1))){
banks$x[[bank]] = c(banks$x[[bank]], data$x[ix][i-1] + ( ( (data$x[ix][i] - data$x[ix][i-1]) / nr_of_pts ) * ido ) )
banks$y[[bank]] = c(banks$y[[bank]], data$y[ix][i-1] + ( ( (data$y[ix][i] - data$y[ix][i-1]) / nr_of_pts ) * ido ) )
}
}
}
Currently I'm doing it with a loop. Which is slow but works.
The suggestion by G5W is working! However, it does not incorporate the blue dots in the orange dots. Of course I can add the blue dots later to the interpolated orange ones. But I need the order of the dots intact for later processing.
Since I think G5W is an expert in R, I don't think that there is a one-line-command to do this. Thus, I stick to loop I have. Here is a plot of the timing (I performed 10 runs to do the boxplots):
Note: The absolute run time is decreased here, since I set the minimum distance quite high.