blockSizeCluster.R 543 B

12345678910111213141516171819202122
  1. blockSizeCluster <- function(x, var = 8) {
  2. # uses blockSize to get an idea of blockSize
  3. estim <- raster::blockSize(x)$nrows[1]
  4. at <- 1
  5. ind2 <- 0
  6. res <- list()
  7. while (at <= nrow(x)) {
  8. ind2 <- ind2 + 1
  9. atin <- at
  10. size <- sample(max(1, (estim-var)):(estim + var), 1) # min is 1 row
  11. at <- (at + size)
  12. if (at > nrow(x))
  13. size <- nrow(x)-(atin-1)
  14. res[[ind2]] <- list(row=atin,nrows=size)
  15. }
  16. res <- matrix(unlist(res),byrow=T,ncol=2)
  17. res <- list(row=res[,1],nrows=res[,2],n=nrow(res))
  18. return(res)
  19. }