An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20060412/a6b6691b/attachment.pl>
Interpolating along an XY path
3 messages · Rob Schick, Barry Rowlingson, Michael Sumner
Rob Schick wrote:
I have a series of x,y coordinates that represent a movement path of a tagged animal. I want to regularize the track, but approx interpolates over the range of x's as opposed to treating the track as an ordered sequence. I've tried coercing it into a time series, but this only seems to work when the X's constantly increase.
What exactly do you mean by 'regularize'? Have you got (x,y,t) data for spotting an animal at point (x,y) at time t where t is irregular, and you want to 'regularize' in t? Or do you want to regularize in space, so you end up with points all the same distance apart? That might not be possible depending on the spacing of your points... I think you're going to end up interpolating between pairs of points. Its quite easy to interpolate points between (x0,y0) and (x1,y1), the coords are just (x0+(1:N)*dx, y0+(1:N)*dy) where dx is (x1-x0)/N and similarly for y. Or I might be one off there... Barry
Rob Schick wrote:
I have a series of x,y coordinates that represent a movement path of a tagged animal. I want to regularize the track, but approx interpolates over the range of x's as opposed to treating the track as an ordered sequence. I've tried coercing it into a time series, but this only seems to work when the X's constantly increase. The following dummy track provides a glimpse of the problem with approx:
If you treat the x's and y's separately with approx you can get what you want (although I'm sure some careful thought would produce a better use of approx): x <- c(1,3,5,5,5,4,2,1.5) y <- c(1,1,1,2,3,3,3,3) xypair <- cbind(x,y) xypair rownames(xypair) <- 1:length(x) plot(x,y,type='l') points(xypair) text(x,y,rownames(xypair),offset=.5,pos=2) points(approx(xypair[,1],n=30)$y, approx(xypair[,2],n=30)$y,col=3,pch="*") BTW, I have a package for animal track data that contains a function called equalTime - it interpolates points in space (euclidean) based on an (approximation to an) equal time interval to create regular spaced points in time, assuming straight motion between fixes. You might find it useful. It's never really been finished, but I use it especially for the S4 validation of trajectory with "trip", and for quick speed filtering and time spent gridding. http://staff.acecrc.org.au/~mdsumner/Rutas/ HTH, Mike.