# NOT RUN {
# select a subset of a RasterLayer
r <- raster(nrow=10, ncol=10)
values(r) <- 1:ncell(r)
plot(r)
s <- select(r) # now click on the map twice
# plot the selection on a new canvas:
x11()
plot(s)
# select a subset of a SpatialPolygons object
p1 <- rbind(c(-180,-20), c(-140,55), c(10, 0), c(-140,-60), c(-180,-20))
hole <- rbind(c(-150,-20), c(-100,-10), c(-110,20), c(-150,-20))
p2 <- rbind(c(-10,0), c(140,60), c(160,0), c(140,-55), c(-10,0))
p3 <- rbind(c(-125,0), c(0,60), c(40,5), c(15,-45), c(-125,0))
pols <- SpatialPolygons( list( Polygons(list(Polygon(p1), Polygon(hole)), 1),
Polygons(list(Polygon(p2)), 2), Polygons(list(Polygon(p3)), 3)))
pols@polygons[[1]]@Polygons[[2]]@hole <- TRUE
plot(pols, col=rainbow(3))
ps <- select(pols) # now click on the map twice
ps
# }
Run the code above in your browser using DataLab