Page MenuHomec4science

split_tiff.py
No OneTemporary

File Metadata

Created
Mon, Apr 28, 14:03

split_tiff.py

import os
from osgeo import gdal
in_path = '/work/hyenergy/raw/SwissTopo/RGB_25cm/data_orig/2014/'
input_filename = 'SI_25_2014_1164-21'
out_tmp='/work/hyenergy/raw/SwissTopo/RGB_25cm/data_resized/crop_tool/'
os.system( "mkdir "+str(out_tmp)+str(input_filename))
out_path = out_tmp+input_filename+"/"
tile_size_x = 250
tile_size_y = 250
ds = gdal.Open(in_path + input_filename + ".tif")
band = ds.GetRasterBand(1)
xsize = band.XSize
ysize = band.YSize
input_filename_mod=input_filename.replace('-', '_')
for i in range(0, xsize, tile_size_x):
for j in range(0, ysize, tile_size_y):
com_string = "gdal_translate -of PNG -srcwin " + str(i)+ ", " + str(j) + ", " + str(tile_size_x) + ", " + str(tile_size_y) + " " + str(in_path) + str(input_filename) + ".tif" + " " + str(out_path) + str(input_filename_mod) + "_" + str(i) + "_" + str(j) + ".png"
os.system(com_string)
#os.system( "ls "+str(out_path) )
os.system( "rm "+str(out_path)+ "*.aux.xml" )
#os.system( "mkdir "+str(out_path)+ "original" )
#os.system( "mkdir "+str(out_path)+ "original/PV" )
#os.system( "mkdir "+str(out_path)+ "original/noPV" )
#os.system( "mkdir "+str(out_path)+ "labels" )
#os.system( "mkdir "+str(out_path)+ "labels/PV" )
#os.system( "mkdir "+str(out_path)+ "labels/noPV" )
# com_string = "gdal_translate -of GTIFF -srcwin

Event Timeline