2

I have nearly 1000 generic binary images, i.e., headerless, band sequential and binary (16-bit signed integer). I have been succesfully able to load these with package 'raster' only when I create an associated .hdr file with the same name as the image.

Hence I would like to create an associated .hdr file for each image, with the following information;

ENVI
description = {
  AVHRR_GIMMS 8km global NDVI x1000}
samples = 2160
lines   = 4320
bands   = 1
header offset = 0
file type = ENVI Standard
data type = 2
interleave = bsq
sensor type = AVHRR
byte order = 1

I am drawing a blank on how to accomplish this. I don't have any programming skills outside of R.

Any suggestions? Is there a more efficient way to accomplish this (e.g., specifying a single header for all files)?

This question is similar to this (presently) unanswered question, except I suspect it may be more straightforward in R than Arcgis.

1 Answer 1

1

I came up with a relatively simple work-around;

#First I create an object containing all the image file names;
mylist<- list.files(path= "C:/myimages/")

#then an object with the content for the header file
x<-"ENVI
description = {
  AVHRR_GIMMS 8km global NDVI x1000}
samples = 2160
lines   = 4320
bands   = 1
header offset = 0
file type = ENVI Standard
data type = 2
interleave = bsq
sensor type = AVHRR
byte order = 1"

#Then I paste the '.hdr' extension to the file names (because I don't know how to do this with write() in the next step)    

mylist.hdr<-paste(mylist,".hdr",sep="")

#and last execute a for loop that creates a file with the header content for each name in the file list
for(i in mylist.hdr) {
  write(x,i)
}

I'm certain there is a better way to go about this, but this is functional at least for this one application. Please share any other ideas.

1
  • Other options could be to do esentially the same thing with GDAL's VRT, or raster's .grd format, or write R functions to matrix(readBin(...)) etc - they all amount to the same thing. Note that your ENVI version doesn't have georeferencing or projection, but presumably it could have, and the other pathways could/should too.
    – mdsumner
    Sep 15, 2014 at 4:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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