Reputation: 8200
I want to read and stack several .grd files and export it as .nc file in R. I am using the following commands
library(raster)
library(ncdf4)
library(RNetCDF)
library(rgdal)
files <-list.files(path="G:/Gridded data/",
pattern="GRD", all.files=FALSE, full.names=TRUE,recursive=TRUE)
s <- stack(files)
rstack <- raster(files[1])
But it is giving the following error
Error in .local(.Object, ...) : Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer", : Cannot create a RasterLayer object from this file. Can anyone help? thanks in advance
Upvotes: 0
Views: 5059
Reputation: 47696
I would try pattern="\\.grd$"
(this means, the file ends on ".grd"). Or at least pattern="grd"
instead of pattern="GRD"
. (or use ignore.case = TRUE
)
files <- list.files(path="G:/Gridded data/", pattern="\\.grd$", full.names=TRUE,recursive=TRUE)
Upvotes: 2