[R-sig-Geo] extract cell numbers from raster along a line

Robert Hijmans r.hijmans at gmail.com
Fri Mar 18 23:25:33 CET 2011


> I'd like to extract celle numbers from a raster using a line, but it seems 
> the cellnumbers=TRUE option isn't working with lines in raster::extract. 

Etienne, 

It is not working because "cellnumbers" is currently only an argument for
extracting values from a Raster* for polygons. That's what the docs say. But
I'll also implement if for lines.  

In your example it is easy to extract cell numbers for the line

> r[] = 1:ncell(r)
> extract(r, l) 
[[1]]
[1]  4  5  8  9 12 13 16 17

> I'm also not sure I get the order in which the values are returned, but it
> seems
>  it is not from the begining of the line to the end or reverse. 

The values are first in row order, and then in column order.  Not in the
order of the coordinates of the line(s).

Robert

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



More information about the R-sig-Geo mailing list