# NOT RUN {
p <- system.file('exdata', 'soybean.tif', package = 'hyperbrick')
im <- brick(p)
print(im)
# view band-3
plot(im[[3]], col = gray.colors(20), asp = 0)
# draw a spatial polygon on image
pol <- Polygon(extent(c(40, 85, 50, 150)))
lines(pol)
# rotate and shift the spatial polygon
new_pol <- affineCoords(pol, angle = -3, xy_shift = c(-11, 0))
plot(im[[3]], col = gray.colors(20), asp = 0)
lines(new_pol)
# do some analysis within it, like:
new_pols <- SpatialPolygons(list(Polygons(list(Polygon(new_pol)), "id0")))
plot(mask(im[[3]], new_pols))
mean(extract(im[[3]], new_pols)[[1]])
# }
Run the code above in your browser using DataLab