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

gdal arguments to project ... #1269

Closed
scbrown86 opened this issue Sep 6, 2023 · 2 comments
Closed

gdal arguments to project ... #1269

scbrown86 opened this issue Sep 6, 2023 · 2 comments

Comments

@scbrown86
Copy link

scbrown86 commented Sep 6, 2023

When trying to project a spatraster, its not possible to provide any additional gdal arguments to writeRaster through ..., despite the documentation saying that ... additional arguments for writing files as in writeRaster. This is because there is already a gdal argument present in project. Could this functionality be fixed so that additional arguments can be passed through? Maybe through a named list?

## SpatRaster
a <- rast(ncols=40, nrows=40, xmin=-110, xmax=-90, ymin=40, ymax=60, 
          crs="+proj=longlat +datum=WGS84")
values(a) <- 1:ncell(a)
newcrs="+proj=lcc +lat_1=48 +lat_2=33 +lon_0=-100 +datum=WGS84"
b <- rast(ncols=94, nrows=124, xmin=-944881, xmax=935118, ymin=4664377, ymax=7144377, crs=newcrs)
w <- project(a, b)

# save with compression
writeRaster(w, paste0(tempfile(),".tif"),
            gdal = c("COMPRESS=LZW", "PREDICTOR=3"))

# project and save to file
## works
w <- project(a, b, filename = paste0(tempfile(),".tif"))

# project and save to file with gdal options
## fails
w <- project(a, b, filename = paste0(tempfile(),".tif"),
             gdal = c("COMPRESS=LZW", "PREDICTOR=3"))
Error in if (gdal) { : the condition has length > 1
@scbrown86
Copy link
Author

Turns out that this is just a documentation fix. The options can be passed using a named list.

## works  
w <- project(a, b, filename = paste0(tempfile(),".tif"),
             wopt = list(gdal = c("COMPRESS=LZW", "PREDICTOR=3")))

@rhijmans
Copy link
Member

rhijmans commented Sep 6, 2023

Thank you for reporting this. You can indeed use "wopt" but that should not be necessary (except with functions where the ellipses are used for something else, but that is not the case here). I have changed argument "gdal" to "use_gdal" to avoid this issue.

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

2 participants