Skip to content

Instantly share code, notes, and snippets.

@JimShady
Last active April 28, 2023 13:21
Show Gist options
  • Save JimShady/30c101c8db681c6fce2b8e967e32b452 to your computer and use it in GitHub Desktop.
Save JimShady/30c101c8db681c6fce2b8e967e32b452 to your computer and use it in GitHub Desktop.
Confusion around gdal options in terra
# This works
test_extent <- ext(rast("lk_run_2023-04-27-15-05-37_30m_aal.tif"))
rast_input <- rast("global_commercial_base_annual_average_damage_ratio.tif", win = test_extent)
lapp(rast_input,
fun = function(x) {x/10000},
filename = "global_commercial_base_annual_average_damage_ratio_floating_point.tif",
wopt = list(datatype = "FLT4S"),
overwrite = TRUE)
# This does not
test_extent <- ext(rast("lk_run_2023-04-27-15-05-37_30m_aal.tif"))
rast_input <- rast("global_commercial_base_annual_average_damage_ratio.tif", win = test_extent)
lapp(rast_input,
fun = function(x) {x/10000},
filename = "global_commercial_base_annual_average_damage_ratio_floating_point.tif",
wopt = list(datatype = "FLT4S"),
overwrite = TRUE,
gdal = c("TILED = YES", "BLOCKXSIZE = 128", "BLOCKYSIZE = 128"))
Error in (function (x) :
unused argument (gdal = c("TILED = YES", "BLOCKXSIZE = 128", "BLOCKYSIZE = 128"))
Error: [lapp] cannot use 'fun'. The number of values returned is less than the number of input cells.
(returning: 1, expecting: 9000)
Perhaps the function is not properly vectorize
@mdsumner
Copy link

fwiw, here's what I'm messing around with - my tif is 86400x43200 I expect yours is much bigger if its compressed

https://gist.github.com/mdsumner/abc467acfb747af3c5d20fe6447cdef8

interested to flesh these out, and help build a resource, maybe at https://github.com/gdal4al/

good night :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment