I am trying to use GDAL to read and write images in ENVI format (for example a .bsq file with an associated .hdr file). The GDAL Formats Info page states "Starting with GDAL 1.10, all ENVI header fields will be stored in the ENVI metadata domain.". If that is the case, how should I access them?
I am using the Python bindings with GDAL 1.9.2 (the latest at this time of writing), and have tried getting all of the metadata:
image.GetMetadata()
which gives me a list of the band 'names' as displayed in ENVI, but that's about it. I've also tried specifically asking for the ENVI metadata domain, as instructed on the GDAL information page linked above:
image.GetMetadata('ENVI')
but that doesn't return anything.
Is there a way to get other metadata from the ENVI file, or will I have to parse the header file myself?
Furthermore, even writing the band names (the ones that seem to be returned when I run GetMetadata()
) using SetMetadata()
doesn't seem to put them in the .hdr file.
Can anyone shed any light on this?
Best Answer
GDAL 1.10 hasn't been released yet. Beta 1 was released a short while ago or if you're using Windows, you can grab a build of the current trunk (1.10dev) from GISInternals.
If you're stuck with 1.9.2 for a while, here's some code to parse envi headers (envi.py)
Some more code that uses regexes to parse a header: