Reproducible example from my dataset;
library(terra)
ext1_boreal <- ext(-154.529, -104.855, 47.663, 70.4789)
x <- rast(ext1_boreal, res=.1, crs="epsg:4326")
values(x) <- 1:ncell(x)
ext_EcoZone1 <- ext(-140.999, -122.812, 56.408, 64.700)
EcoZone2 <- vect(ext_EcoZone1, crs="epsg:4326")
x <- mask(x, EcoZone2)
f <- "D:/GitHub/MyProject/Outputs/Rasters/Explanatory/Testx.asc"
writeRaster(x, filename=f, overwrite=TRUE)
The problem:
Warning: D:/GitHub/MyProject/Outputs/Rasters/Explanatory/Testx.asc: Couldn't find data values in ASCII Grid file. (GDAL error 1)Error: [rast] cannot open this file as a SpatRaster: D:/GitHub/MyProject/Outputs/Rasters/Explanatory/Testx.asc
Why is this warning coming up? Using: Package terra version 1.7-71, R version 4.3.3.
I have been unable to export an acs (ESRI ASCII) Spatraster for my data. I can export tif without issues. I need the acs format to run another piece of software that runs off acs format. I am able to take Spatraster tif files into QGIS and individual save them as acs files that can then be imported back into R.
I get the same error with the CRAN version of "terra" (1.7-71). The reason is that the NODATA value written to file is "nan"
I do not see that problem in the development version of "terra"
You can install the development version with
Note that this also works without the separate call to
writeRasterI see that this works for integer rasters, but not for rasters with real (floating point) values. The odd thing is that it does work with the example (if you use
x/2). This may be because it is not a very large dataset and GDAL detects the real numbers in the first part of the file, whereas it does not do that correctly with your data).This should be fixed but here is a work-around. You can set the
NAflagmanually so a value outside of the range of your actual values. For example