Commit ec181c26 authored by Manuel Grizonnet's avatar Manuel Grizonnet

ENH: replace gdal translate to API calls

parent a4f9430e
......@@ -171,7 +171,8 @@ class snow_detector :
gb_path_extracted=op.join(self.path_tmp, "green_band_extracted.tif")
if gb_dataset.RasterCount > 1:
print "extracting green band"
call_subprocess(["gdal_translate", "-of","GTiff","-ot","Int16","-a_nodata", str(self.nodata),"-b",str(gb_no),gb_path,gb_path_extracted])
#Use gdal 2 python API
gdal.Translate(gb_path_extracted,gb_path,format = 'GTiff', outputType = gdal.GDT_Int16, noData=self.nodata, bandList = [gb_no])
else:
copyfile(gb_path, gb_path_extracted)
......@@ -183,7 +184,7 @@ class snow_detector :
rb_path_extracted=op.join(self.path_tmp, "red_band_extracted.tif")
if rb_dataset.RasterCount > 1:
print "extracting red band"
call_subprocess(["gdal_translate", "-of","GTiff","-ot","Int16","-a_nodata", str(self.nodata),"-b",str(rb_no),rb_path,rb_path_extracted])
gdal.Translate(rb_path_extracted,rb_path,format = 'GTiff', outputType = gdal.GDT_Int16, noData=self.nodata, bandList = [rb_no])
else:
copyfile(rb_path, rb_path_extracted)
......@@ -195,8 +196,7 @@ class snow_detector :
sb_path_extracted=op.join(self.path_tmp, "swir_band_extracted.tif")
if sb_dataset.RasterCount > 1:
print "extracting swir band"
call_subprocess(["gdal_translate", "-of","GTiff","-ot","Int16","-a_nodata", str(self.nodata),"-b",str(sb_no),sb_path,sb_path_extracted])
gdal.Translate(sb_path_extracted,sb_path,format = 'GTiff', outputType = gdal.GDT_Int16, noData=self.nodata, bandList = [sb_no])
else:
copyfile(sb_path, sb_path_extracted)
......@@ -219,10 +219,12 @@ class snow_detector :
print "resolution is different among band files"
#gdalwarp to max reso
max_res = max(gb_resolution, rb_resolution, sb_resolution)
print "cubic resampling to " + str(max_res) + "of resolution"
print "cubic resampling to " + str(max_res) + " meters."
call_subprocess(["gdalwarp", "-overwrite","-r","cubic","-tr", str(max_res),str(max_res),gb_path_extracted,gb_path_resampled])
call_subprocess(["gdalwarp", "-overwrite","-r","cubic","-tr", str(max_res),str(max_res),rb_path_extracted,rb_path_resampled])
call_subprocess(["gdalwarp", "-overwrite","-r","cubic","-tr", str(max_res),str(max_res),sb_path_extracted,sb_path_resampled])
#gdal.Warp(gb_path_resampled,gb_path_extracted,resampleAlg = gdal.GRIORA_Cubic, xRes = max_res,yRes = max_res)
else:
gb_path_resampled=gb_path_extracted
rb_path_resampled=rb_path_extracted
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment