[R-sig-Geo] extract function - return the ID of the polygon
Robert Hijmans
r.hijmans at gmail.com
Sat Jan 22 22:59:18 CET 2011
Brian,
> I would like to know how to also reurn the ID of the polygon when using
> the 'extract' function to extract raster cell values.
The values are returned in the order of the polygons. So the IDs would be
1:n, or in your example, poly$FID. Isn't that enough?
> 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.
It would also be much faster to make a RasterStack and use 'extract' only
once.
>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.
That works if the polygons do not overlap. 'extract' also works if the
polygons do overlap.
If you go along your route, which could be handy if you repeatedly want to
extract values, I think I would first do 'rasterize' (once), but then
(repeatedly) use 'zonal', or perhaps 'crosstab'.
> A function that might be handy (and fast) in the future might be of the
> cellFrom* function family
I agree. I think I'll add cellFromPolygons and cellFromLines
Best, Robert
--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/extract-function-return-the-ID-of-the-polygon-tp5951128p5951691.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
More information about the R-sig-Geo
mailing list