24 from __future__
import print_function
25 from osgeo
import gdal
27 import osgeo.gdalconst
as gdalc
30 if len(sys.argv) != 6:
31 print(
"Usage: window.py <raster> <x> <y> <xsize> <ysize>")
32 print(
"\traster - GDAL supported dataset")
33 print(
"\tx - column - 1..N where N is raster X dimension")
34 print(
"\ty - row - 1..N where N is raster Y dimension")
35 print(
"\txsize - x-dimension of requested window (xsize <= xsize of raster - x)")
36 print(
"\tysize - y-dimension of requested window (ysize <= ysize of raster - y)")
40 if gt[0] == 0.0
and gt[1] == 1.0
and gt[3] == 0.0
and gt[5] == 1.0:
47 xgeo = gt[0] + gt[1] * x + gt[2] * y
48 ygeo = gt[3] + gt[4] * x + gt[5] * y
55 inxoff = int(sys.argv[2])
56 inyoff = int(sys.argv[3])
57 inxsize = int(sys.argv[4])
58 inysize = int(sys.argv[5])
59 print(
"=== INPUT ===")
60 print(
"File: %s" % infile)
62 print(
"- upper-left: %d x %d" % (inxoff, inyoff))
63 print(
"- dimensions: %d x %d" % (inxsize, inysize))
65 ds = gdal.Open(infile, gdalc.GA_ReadOnly);
67 sys.exit(
'Cannot open input file: ' +
str(infile))
69 xsize = ds.RasterXSize
70 ysize = ds.RasterYSize
71 print(
"=== RASTER ===")
72 print(
"- dimensions: %d x %d" % (xsize, ysize))
74 if inxsize > xsize
or inysize > ysize
or inxoff > xsize
or inyoff > ysize:
75 print(
"Invalid size of input window")
78 gt = ds.GetGeoTransform()
79 res = ( gt[1], gt[5] )
80 ulp = ( gt[0], gt[3] )
81 rot = ( gt[2], gt[4] )
84 print(
"- pixel size:", res)
85 print(
"- upper left:", ulp)
86 print(
"- rotation :", rot)
88 print(
"No georeferencing is available")
91 print(
"=== WINDOW ===")
def calculate_corner(gt, x, y)