26 from osgeo
import gdal
28 import osgeo.gdalconst
as gdalc
31 if len(sys.argv) != 6:
32 print "Usage: window.py <raster> <x> <y> <xsize> <ysize>"
33 print "\traster - GDAL supported dataset"
34 print "\tx - column - 1..N where N is raster X dimension"
35 print "\ty - row - 1..N where N is raster Y dimension"
36 print "\txsize - x-dimension of requested window (xsize <= xsize of raster - x)"
37 print "\tysize - y-dimension of requested window (ysize <= ysize of raster - y)"
41 if gt[0] == 0.0
and gt[1] == 1.0
and gt[3] == 0.0
and gt[5] == 1.0:
48 xgeo = gt[0] + gt[1] * x + gt[2] * y
49 ygeo = gt[3] + gt[4] * x + gt[5] * y
56 inxoff = int(sys.argv[2])
57 inyoff = int(sys.argv[3])
58 inxsize = int(sys.argv[4])
59 inysize = int(sys.argv[5])
61 print "File: %s" % infile
63 print "- upper-left: %d x %d" % (inxoff, inyoff)
64 print "- dimensions: %d x %d" % (inxsize, inysize)
66 ds = gdal.Open(infile, gdalc.GA_ReadOnly);
68 sys.exit(
'Cannot open input file: ' + str(infile))
70 xsize = ds.RasterXSize
71 ysize = ds.RasterYSize
72 print "=== RASTER ==="
73 print "- dimensions: %d x %d" % (xsize, ysize)
75 if inxsize > xsize
or inysize > ysize
or inxoff > xsize
or inyoff > ysize:
76 print "Invalid size of input window"
79 gt = ds.GetGeoTransform()
80 res = ( gt[1], gt[5] )
81 ulp = ( gt[0], gt[3] )
82 rot = ( gt[2], gt[4] )
85 print "- pixel size:", res
86 print "- upper left:", ulp
87 print "- rotation :", rot
89 print "No georeferencing is available"
92 print "=== WINDOW ==="
def calculate_corner(gt, x, y)