Error: cannot open this file as a SpatRaster #39
-
Hello, I am trying to run a patch-based model using the RangeShifter platform in RStudio, but I am encountering a few errors when trying to load in my habitat patches. The habitat patches were created in ArcMap and converted into raster format, then the attributes were exported as an asc. file. I am trying to run the following code to read in the habitat patches: patches <- terra::rast(paste0(dirpath,'Inputs/Raster_MCE_Std2_10_largest_areas.asc')) But I receive the following errors: I have installed and loaded all the relevant packages (raster, terra, rgdal). I do not understand the errors here and I was hoping someone may be able to help. I have attached the asc. file. I appreciate any help! Many thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi, |
Beta Was this translation helpful? Give feedback.
Hi,
looking at the content of your file it seems that the file format is wrong and not in a raster format. You probably need to go back to ArcMap and make sure to rasterize your landscape (based on the content of your file it might be a spatial polygon or vector?).
A typical .asc raster file would have a header with 6 rows defining the parameters 'ncols', 'nrows', 'xllcorner', 'yllcorner', 'cellsize' and 'NODATA_value', then following the cell values for each grid cell. You can google 'asc raster file example' for examples.