Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

offsets from dimension,extent only #14

Open
mdsumner opened this issue Sep 19, 2024 · 0 comments
Open

offsets from dimension,extent only #14

mdsumner opened this issue Sep 19, 2024 · 0 comments

Comments

@mdsumner
Copy link
Member

assuming snapped here, some kind of refactor is required

library(filearchy)
library(dplyr)
dsn <- system.file("extdata/gebco_ovr5.vrt", package = "filearchy", mustWork = TRUE)
## parallelize here
#future::plan(multicore)
tiles <- gdal_tiles(dsn, dry_run = TRUE)

tiles |> filter(zoom == 1)
profile <- filearchy:::tile_profile()

g <- grout::grout(c(512, 512), profile$extent, blocksize = c(256, 256))
grout::tile_zoom
vaster::col_from_cell
## we are already snapped to the output tiling, no dangle here
tile_index0 <- function(dimension, extent = NULL, block = 256) {
  block <- rep(block, length.out = 2L)
  
  nc <- prod(dimension)
  tile <- seq_len(nc)

  offsetX <- (vaster::col_from_cell(dimension, tile) - 1) * block[1]
  offsetY <- (vaster::row_from_cell(dimension, tile) - 1) * block[2]
  nX <- rep(block[1], nc)
  nY <- rep(block[2], nc)


  res <- diff(extent)[c(1, 3)] / dimension
  minX <- extent[1] + offsetX * res[1]
  maxX <- extent[1] +  (offsetX + nX) * res[1]
  minY <- extent[4] +  (offsetY + nY)     * -res[2]
  maxY <- extent[4] +  offsetY * -res[2]

  tile_col <- (offsetX %/% block[1]) + 1
  tile_row <- (offsetY %/% block[2]) + 1

tibble::tibble(tile = tile, offset_x = offsetX, offset_y = offsetY, 
               tile_col = tile_col, tile_row = tile_row, 
               ncol = nX, nrow = nY, xmin = minX, xmax  = maxX, ymin = minY, ymax = maxY)
}
tile_index0(c(256, 256), profile$extent)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant