You could crop and mask the raster to each region and then use "sampleRandom" to create a random sample of the specific region(s). This should speed things up considerably.
require(raster)
r1 <- raster(ncol=10, nrow=10, xmn=0, ymn =0, xmx=100, ymx=100)
r1[] <- runif(ncell(r1),0,100)
r2 <- raster(ncol=10, nrow=10, xmn=0, ymn =0, xmx=100, ymx=100)
r2[] <- runif(ncell(r1),100,200)
r3 <- raster(ncol=10, nrow=10, xmn=0, ymn =0, xmx=100, ymx=100)
r3[] <- runif(ncell(r1),200,300)
r <- stack(r1, r2, r3)
names(r) <- c("r1", "r2", "r3")
region1 <- rbind(c(0,0), c(50,0), c(50,50), c(0,50), c(0,0))
region2 <- rbind(c(50,0), c(100,0), c(100,50), c(50,50), c(50,0))
region3 <- rbind(c(0,50), c(50,50), c(50,100), c(0,100), c(0,50))
region4 <- rbind(c(50,50), c(100,50), c(100,100), c(50,100), c(50,50))
polys <- SpatialPolygons(list(Polygons(list(Polygon(region1)), "region1"),
Polygons(list(Polygon(region2)), "region2"),
Polygons(list(Polygon(region3)), "region3"),
Polygons(list(Polygon(region4)), "region4")))
rs <- as.data.frame(array(0, dim=c( 0, length(names(r))+1 )))
names(rs) <- c("REGION", names(r))
for(i in 1:length(polys)){
region <- polys[i]
cr <- crop(r, extent(region), snap="out")
m <- rasterize(region, cr)
mr <- mask(x=cr, mask=m)
rs.mat <- sampleRandom(mr, 10, na.rm=TRUE)
rs.mat <- cbind(REGION=i, rs.mat)
rs <- rbind(rs, as.data.frame(rs.mat) )
}
print( rs )
Best Answer
May be off topic because it is not a direct ArcGis solution:
For an simple routine you could use the GDAL tools gdal_merge.py in conjuction with gdal_translate to merge and cut the geo-tiffs on a data level (geotiff for example).
You will need python as well as gdal. You could install osgeo4w for windows, to get both tools in one step.
The "best-how-to-aspect" depends on the location and extention of the image cut's in the tile set you want to proceed. In a worst case it will have a fractal nature. A wild mix between many small footprints on the image borders at one side versus one big footprint overlapping many image tiles.
At least you could use a common resampling approach:
calculate and sort the image cuts vs. the tiles that are involved and store them in a list.
resort the list and create an list of unique merge tasks
merge the tiles and procced the cut for each corresponding cut-image (pseudo code)