[R-sig-Geo] extract function - return the ID of the polygon

Brian Oney zenlines at gmail.com
Sat Jan 22 17:40:06 CET 2011


Hello list,
I would like to know how to also reurn the ID of the polygon when using 
the 'extract' function to extract raster cell values.
Honestly, I am just extracting and using the cell numbers to extract 
values for these polygons in other raster layers for the same extent, 
because it is so much faster.
Right now the one idea I have for the raster package would be to 
rasterize the polygons and then extract using the same polygons and then 
take the cell numbers and their values so that I would have a cell with 
a value for the polygon to which it corresponds.

poly.rast <- rasterize(poly, rast, field=c(poly$FID))
ex <- extract(poly.rast, poly, cellnumbers=T)

I don't know how this would work with much larger files. My current 
operation corresponds to ~12000 cells and could be faster.
Could be the problem that it is saturday and my brain is refusing to work...

A function that might be handy (and fast) in the future might be of the 
cellFrom* function family (with an argument to carry over a polygon 
field ID etc.).
Thanks for the help!
Best,
Brian



More information about the R-sig-Geo mailing list