3

How to open .grd raster layers in QGIS (or any other GIS)?

I have looked through previous questions, but not found any answer. My raster layers are outputs from running bfastSpatial in R and I can't seem to open them in QGIS. I have also been unsuccessful in converting the format to .tif so I am hoping there is some other option.

4

There is no gdal driver for the native format of the raster package (gri + grd), that is why you cannot directly open it in QGIS. One workaround to open data in QGIS without duplicating them is to create an additional header file using the hdr() function of the raster package.

library(raster)

b <- brick('/path/to/file.grd')
hdr(b, format = 'ENVI')

Point to the .gri file when opening with QGIS

1

Use raster package to convert your files to .tif before loading them in QGIS. I will use a reproducible example from the package example:

library(bfastSpatial)

srdir <- dirout <- file.path(dirname(rasterTmpFile()), 'bfmspatial_2')
dir.create(dirout, showWarning=FALSE)

# Get the directory where the Landsat archives are stored
dir <- system.file('external', package='bfastSpatial')

# Run the batch line
processLandsatBatch(x=dir, pattern=glob2rx('*.zip'), outdir=dirout, srdir=srdir, delete=TRUE, vi='ndvi', mask='fmask', keep=0, overwrite=TRUE)

list <- list.files(dirout, pattern=glob2rx('*.grd'), full.names=TRUE)

The above code creates a .grd image. Now use raster package to convert files.

r <- raster::raster(list[[1]])

raster::writeRaster(r,filename = "image_name", format = "GTiff")

Also, you can create a loop to automate all the process.

for(i in 1:length(list)){
  r <- raster::raster(list[[i]])
  name <- gsub(pattern = ".*bfmspatial_2/",replacement = "", r@file@name) # your folder here (pattern)
  name <- gsub(pattern = ".grd",replacement = "", name)
  raster::writeRaster(r,filename = name, format = "GTiff") 
}

I hope it helps you

  • I have tried but I get this error : Fehler in .getGDALtransient(x, filename = filename, options = options, : filename exists; use overwrite=TRUE – dtanon Nov 8 '16 at 9:54
  • I just replaced ".*bfmspatial_2/" with my folder – dtanon Nov 8 '16 at 9:56
  • Did you list files? Paste a part of your results to see what happens. – aldo_tapia Nov 8 '16 at 11:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.