[R-sig-Geo] How to use select function in raster with use="pol"?

Robert Buitenwerf buitenwerf at em.uni-frankfurt.de
Thu Mar 14 09:44:10 CET 2013


Dear all,

The select function in raster seems really neat and works well for rectangles i.e. use="rec".

I can't get good results for selecting polygons though i.e. use="pol".

I do:

r <- raster(nrow=10, ncol=10)
r[] <- 1:ncell(r)
plot(r)
s <- select(r, use="pol")

After clicking on the image multiple times in the shape that I want I press escape (running R on 64bit Windows 7). A polygon of the wanted shape is drawn onto the raster, but the new object s is not created. I get this error:

Error in as.vector(y) : no method for coercing this S4 class to a vector


Perhaps I shouldn't use escape to tell select I'm done, but I can't figure out what else to do...

It would also be nice if the polygon lines were drawn while clicking the image (not only afterwards) so that you can see what you're doing?


Thanks,
Robert



More information about the R-sig-Geo mailing list