"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)
I believe that you have done everything right but the neatline is crappy.
I checked the first coordinate of the neatline by using the formula for affine transformation from http://www.gdal.org/gdal_datamodel.html
Xgeo = GT(0) + Xpixel*GT(1) + Yline*GT(2)
Ygeo = GT(3) + Xpixel*GT(4) + Yline*GT(5)
The GeoTransform parameters of your image are
GT(0)= -7964169,744
GT(1)= 1177,758187
GT(2)= 322,1610457
GT(3)= 6367638,541
GT(4)= 322,229011
GT(5)= -1177,712898
First Xpixel, Yline pair from your formula is
(665.3036244770069, 5720.95251596183)
With these values Xgeo, Ygeo (rounded by Excel) is about the same as the first vertex in your neatline polygon:
-5337539.99, -155619.10 (Was -5337534.907769799232483, -155620.899077162524918)
I feat that you must make an intermediate copy of your map with gdalwarp and measure a better neatline. You are not the first one who has met neatline that does not cover the area of the map image in PDF gdalwarp not clipping neatline properly.
I do not know any GDAL utility that would support directly cropping by neatline but once you know the right pixels and the area to crop is rectangle without rotation you can use gdal_translate with -srswin
-srcwin xoff yoff xsize ysize:
Selects a subwindow from the source image for copying based on pixel/line location.
Best Answer
You can use
gdal_edit.py
: