Skip to content

Commit

Permalink
Merge pull request #90 from njtierney/fix-tile_blocksize
Browse files Browse the repository at this point in the history
Fix `tile_blocksize()` to work with multi-layer rasters
  • Loading branch information
Aariq authored Sep 10, 2024
2 parents fa9db96 + eab4748 commit 68e425f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
6 changes: 3 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# geotargets (development version)

* Created `tar_stars()` and `tar_stars_proxy()` that create `stars` and `stars_proxy` objects, respectively.
* Created `tar_terra_tiles()`, a "target factory" for splitting a raster into multiple tiles with dynamic branching.
* Removes the `iteration` argument from all `tar_*()` functions. `iteration` now hard-coded as `"list"` since it is the only option that works (for now at least).
* Created two helper functions for use in `tar_terra_tiles()`: `tile_grid()` and `tile_blocksize()`.
* Created `tar_terra_tiles()`, a "target factory" for splitting a raster into multiple tiles with dynamic branching (#69).
* Created two helper functions for use in `tar_terra_tiles()`: `tile_grid()` and `tile_blocksize()` (#69, #87, #89).
* Created utility function `set_window()` mostly for internal use within `tar_terra_tiles()`.
* Removes the `iteration` argument from all `tar_*()` functions. `iteration` now hard-coded as `"list"` since it is the only option that works (for now at least).
* Added the `description` argument to all `tar_*()` functions which is passed to `tar_target()`.

# geotargets 0.1.0 (14 May 2024)
Expand Down
2 changes: 1 addition & 1 deletion R/tar_terra_tiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ tile_grid <- function(raster, ncol, nrow) {
#' @export
#' @rdname tile_helpers
tile_blocksize <- function(raster) {
tile_ext <- terra::getTileExtents(raster, terra::fileBlocksize(raster))
tile_ext <- terra::getTileExtents(raster, terra::fileBlocksize(raster)[1,])
n_tiles <- seq_len(nrow(tile_ext))
tile_list <- lapply(
n_tiles,
Expand Down
11 changes: 7 additions & 4 deletions tests/testthat/test-tar-terra-tiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ targets::tar_test("tar_terra_tiles() works", {
list(
tar_target(
my_file,
system.file("ex/elev.tif", package="terra"),
# system.file("ex/elev.tif", package="terra"),
system.file("ex/logo.tif", package = "terra"),
format = "file"
),
tar_terra_rast(
Expand Down Expand Up @@ -46,12 +47,13 @@ targets::tar_test("recombined tiles are equal to original", {
list(
tar_target(
my_file,
system.file("ex/elev.tif", package="terra"),
system.file("ex/elev.tif", package = "terra"),
format = "file"
),
tar_terra_rast(
my_map,
terra::rast(my_file)
#create multi-layer raster for testing
rast(c(my_file, my_file))
),
tar_terra_tiles(
name = rast_split,
Expand All @@ -63,5 +65,6 @@ targets::tar_test("recombined tiles are equal to original", {
targets::tar_make()
targets::tar_load(c(my_map, rast_split))
recombined <- terra::merge(terra::sprc(rast_split))
expect_equal(terra::values(my_map), terra::values(recombined))
expect_equal(terra::values(my_map),
terra::values(recombined))
})

0 comments on commit 68e425f

Please sign in to comment.