"Starting with GDAL 1.10..."
"I am using the Python bindings with GDAL 1.9.2..."
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:
import re
def get_envi_header_dict(hdr):
#Get all "key = {val}" type matches
regex=re.compile(r'^(.+?)\s*=\s*({\s*.*?\n*.*?})$',re.M|re.I)
matches=regex.findall(hdr)
#Remove them from the header
subhdr=regex.sub('',hdr)
#Get all "key = val" type matches
regex=re.compile(r'^(.+?)\s*=\s*(.*?)$',re.M|re.I)
matches.extend(regex.findall(subhdr))
return dict(matches)
if __name__=='__main__':
hdr='''ENVI
description = {
RPC Orthorectification Result [Mon Aug 13 13:38:09 2012] [Mon Aug 13
13:38:09 2012]}
samples = 27856
lines = 30016
bands = 1
header offset = 0
file type = ENVI Standard
data type = 12
interleave = bsq
sensor type = WorldView
byte order = 0
map info = {UTM, 1.000, 1.000, 723000.000, 8129434.000, 5.0000000000e-001, 5.0000000000e-001, 55, South, WGS-84, units=Meters}
coordinate system string = {PROJCS["UTM_Zone_55S",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",10000000.0],PARAMETER["Central_Meridian",147.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]]}
wavelength units = Micrometers
band names = {
Orthorectified (Band 1)}
wavelength = {
0.625000}
'''
print get_envi_header_dict(hdr)
Best Answer
You can install the GDAL library from OSGEO here: http://www.osgeo.org/ , there are also nice Windows binaries located at here thanks to Tamas Szekeres. Just make sure you install the right version for the version of Python your running.
In your Python code you can import the library like so:
Then in your code body, you can get a reference to you raster, say, by iterating over a folder of tif's like below...
Then invoke GDAL to open the raster and get a 'handle' to the data source like:
Use "GetMetadataItem" method to pick out the metadata item you're interested in like so:
You can review other metadata tags here: http://www.gdal.org/gdal_datamodel.html
Close the raster dataset