Skip to content
Prev 11240 / 29559 Next

extract cell numbers from raster along a line

I did notice that, but there was no ==line== section in the doc I have. Is 
my package outdated ?
No, there were no additional arguments for lines specifically. There is one
now (cellnumbers) in the R-Forge version (1.8-6).
Below I show how -- I think -- you can order the values such that they
follow the line.


library(raster)
r <- raster(matrix(1:20, nrow=4)) 
l <- SpatialLines(list(Lines(list(Line(list(x=c(0, 1), y=c(0, 1)))), ID=1))) 
plot(r, asp=1); lines(l) 

a <- extract(r, l, cellnumbers=T)[[1]] 
rc <- rowColFromCell(r, a[,1])
b <- cbind(rc, value=a[,2])

#order top to bottom
b[order(-b[,1], b[,2]), 3]
#order bottom to top
b[order(b[,1], -b[,2]), 3]
# or
rev( b[order(-b[,1], b[,2]), 3] )


--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/extract-cell-numbers-from-raster-along-a-line-tp6185643p6187936.html
Sent from the R-sig-geo mailing list archive at Nabble.com.