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

writeRaster(..., filetype="VRT") crashes R #1720

Closed
brownag opened this issue Jan 21, 2025 · 1 comment
Closed

writeRaster(..., filetype="VRT") crashes R #1720

brownag opened this issue Jan 21, 2025 · 1 comment

Comments

@brownag
Copy link
Contributor

brownag commented Jan 21, 2025

I stumbled across this case when working on #1714. Setting filetype="VRT" with writeRaster() crashes R.

library(terra)
x <- rast(system.file("ex", "elev.tif", package = "terra"))
writeRaster(x, filename = "foo.vrt", filetype = "VRT")

Note it does write a "foo.vrt" file without the source information we get with vrt(x, filename = "foo2.vrt")

So, after crash in a new session we get:

terra::rast("foo.vrt")
#> class       : SpatRaster 
#> dimensions  : 90, 95, 1  (nrow, ncol, nlyr)
#> resolution  : 0.008333333, 0.008333333  (x, y)
#> extent      : 5.741667, 6.533333, 49.44167, 50.19167  (xmin, xmax, ymin, ymax)
#> coord. ref. : lon/lat WGS 84 (EPSG:4326) 
#> source      : foo.vrt 
#> name        : elevation 
#> min value   :         0 
#> max value   :         0 

I figure writeRaster(..., filetype="VRT") is not something folks often try to do, but to avoid a crash the specific value of filetype="VRT" could have an error message that directs the user to to vrt(), or, alternately, passes terra::sources(x) to vrt() and errors for x that exists only in memory.

@rhijmans
Copy link
Member

Thank you, I now get

writeRaster(x, filename = "foo.vrt", filetype = "VRT")
#Error: [writeRaster] Cannot directly write to VRT (see '?vrt')

This error will also occur when writeStart is called from other methods that write raster files.

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