Closed mmrgeodk closed 2 years ago
So you can't load file in Sufer that was created in {terra}
? I ask because it seems that the driver works properly when writing.
library("terra") # v. 1.6.17
r = rast(nrows = 5, ncols = 5, vals = 1:25)
writeRaster(r, "test.grd", filetype = "GS7BG")
describe("test.grd")[1]
#> [1] "Driver: GS7BG/Golden Software 7 Binary Grid (.grd)"
On closer inspection, it seems to be a issue when terra:writeRaster() is used on a raster::raster.
library(raster)
library(terra) # v 1.6.17
r = raster(nrows = 5, ncols = 5, vals = 1:25)
terra::writeRaster(r, "test.grd", filetype = "GS7BG", overwrite = TRUE)
describe("test.grd")[1]
#> [1] "Driver: RRASTER/R Raster"
rt = rast(nrows = 5, ncols = 5, vals = 1:25)
terra::writeRaster(rt, "test2.grd", filetype = "GS7BG", overwrite = TRUE)
describe("test2.grd")[1]
#> [1] "Driver: GS7BG/Golden Software 7 Binary Grid (.grd)"
terra::writeRaster()
requires SpatRaster not Raster* object.
raster::writeRaster()
supports limited number of formats excluding GS7BG
so that's the reason why it doesn't work.
Sorry, I wrote too quickly and {raster}
supports this format too: https://rspatial.github.io/raster/reference/writeFormats.html
Thanks, that was a bug in raster::writeRaster. I now get:
library(raster)
r <- raster(nrows = 5, ncols = 5, vals = 1:25)
writeRaster(r, "surf.grd", format = "GS7BG", overwrite = TRUE)
terra::describe("surf.grd")[1]
#[1] "Driver: GS7BG/Golden Software 7 Binary Grid (.grd)"
Note that although you can call terra::writeRaster
with a RasterLayer
object, what will be used is raster::writeRaster
because the dispatch of the generic writeRaster
depends on the class of x
(the first argument). The package::method
notation can make a difference when another package (probably not importing terra or raster) overwrites writeRaster
, but that is not the case here.
Also note that while terra::writeRaster
has the argument filetype
, raster::writeRaster
has the equivalent argument format
; so you must use format
here.
Thanks for correcting!
writeRaster() does not follow "filetype= " argument when the filename has a ".grd" file extension.
The command writeRaster(any_raster, filename = "any_raster.grd", filetype = "GS7BG") results in a grd-file in raster-format and not in "GS7BG (Golden Software Surfer Binary)" format. The same for other filetypes with .grd file extensions.