print 'initializing warp' print sectional_region, sectional_side warped_filename = '%s%s %s.tif' % (warped_sectionals_path, sectional_region, sectional_side) sectional_to_reference_ct = osr.CoordinateTransformation(sectional_srs, reference_srs) print info.x_min, info.x_max print info.y_min, info.y_max warped_x_pixel_size = 64.0 warped_y_pixel_size = 64.0 corners = [ (info.x_min, info.y_min), (info.x_min, info.y_max), (info.x_max, info.y_min), (info.x_max, info.y_max), ] targ_xmin = None for corner in corners: (x, y) = corner X = sectional_geomatrix[0] + sectional_geomatrix[1] * x + sectional_geomatrix[2] * y Y = sectional_geomatrix[3] + sectional_geomatrix[4] * x + sectional_geomatrix[5] * y (x, y, z) = sectional_to_reference_ct.TransformPoint(X, Y) print corner, x,y if targ_xmin is None: targ_xmin = targ_xmax = x targ_ymin = targ_ymax = y else: targ_xmin = min(targ_xmin, x) targ_xmax = max(targ_xmax, x) targ_ymin = min(targ_ymin, y) targ_ymax = max(targ_ymax, y) warped_xsize = (targ_xmax - targ_xmin) / warped_x_pixel_size + 1 warped_ysize = (targ_ymax - targ_ymin) / warped_y_pixel_size + 1 print warped_xsize, warped_ysize print info.x_max - info.x_min, info.y_max - info.y_min warped_gt = (targ_xmin, warped_x_pixel_size, 0.0, targ_ymax, 0.0, - warped_y_pixel_size) warped_image = gdal.GetDriverByName('GTiff').Create( warped_filename, warped_xsize, warped_ysize, 3, gdal.GDT_Byte, # RGB [ 'TILED=YES' ] ) warped_image.SetProjection( reference_srs.ExportToWkt() ) warped_image.SetGeoTransform( warped_gt ) # warped_image.GetRasterBand(1).SetRasterColorTable(sectional_image.GetRasterBand(1).GetRasterColorTable()) #warped_image.GetRasterBand(1) #warped_image.GetRasterBand(2) #warped_image.GetRasterBand(3) warped_image.GetRasterBand(1).SetNoDataValue(255) warped_image.GetRasterBand(2).SetNoDataValue(0) warped_image.GetRasterBand(3).SetNoDataValue(255) blank_lines = Numeric.ones((warped_ysize, warped_xsize)) * 255 warped_image.GetRasterBand(1).WriteArray(blank_lines,0,0) warped_image.GetRasterBand(2).WriteArray(blank_lines,0,0) warped_image.GetRasterBand(3).WriteArray(blank_lines,0,0) masked_image = None warped_image = None command = './warp "%s" "%s"' % (masked_filename, warped_filename) print command os.system(command) command = 'convert -scale 10%% "%s" "%s.png"' % (warped_filename, warped_filename[:-4]) print command os.system(command)