-
Notifications
You must be signed in to change notification settings - Fork 24
Open
Labels
Description
2+ creation options passed to gdalwarp via the "-co" argument (see GDAL documentation) cause the following error:
Error:
! warp: options error
Hide Traceback
▆
1. └─sf::gdal_utils(...)
2. └─sf:::CPL_gdalwarp(...)Passing each option via a separate "-co" statement should fix this, e.g.
c("-co", "compress=lzw", "-co", "predictor=2")instead of the current call:
c("-co", "compress=lzw", "predictor=2")Minimal reprex (created by ChatGPT):
library(sf)
# Create a temporary raster using sf's built-in dataset
nc = st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
r = stars::st_rasterize(nc["AREA"], dx = 0.1, dy = 0.1)
tmp_in = tempfile(fileext = ".tif")
tmp_out = tempfile(fileext = ".tif")
writeRaster = function(x, filename, ...) {
terra::writeRaster(terra::rast(x), filename, overwrite = TRUE, ...)
}
# Write input raster
writeRaster(r, tmp_in)
# Fails (multiple options in one -co statement)
sf::gdal_utils(
util = "warp",
source = tmp_in,
destination = tmp_out,
options = c("-co", "compress=lzw", "predictor=2")
)
# Works (each option in its own -co statement)
sf::gdal_utils(
util = "warp",
source = tmp_in,
destination = tmp_out,
options = c("-co", "compress=lzw", "-co", "predictor=2")
)