Reputation: 31
Hi: On Windows 7 and I'm calling GDAL_translate.exe and GDALwarp.exe from Python to resample and reproject a one-band geotiff. I tried running GDALwarp by itself, but it complained that it needed georeferencing information in it's input file. Thus, I'm running GDAL_translate first and specifying file corner coordinates via the -a_ullr flag.
I'm stuck on GDAL_translate, which runs, but my output file contains nothing but NaNs and zeros. Does anyone know what I'm doing wrong?
Note that the --config GDAL_DATA flag had to be specified or I'd get 'ERROR 4: Unable to open EPSG support file gcs.csv.'
# learn file upper left coordinate and lower right coordinate
ulXgeo = geoTrans[0] + 0 * geoTrans[1] + 0 * geoTrans[2]
ulYgeo = geoTrans[3] + 0 * geoTrans[4] + 0 * geoTrans[5]
lrXgeo = geoTrans[0] + cols * geoTrans[1] + rows * geoTrans[2]
lrYgeo = geoTrans[3] + cols * geoTrans[4] + rows * geoTrans[5]
cornerCoors = ' ' + str(ulXgeo) + ' ' + str(ulYgeo) + ' ' + str(lrXgeo) + ' ' + str(lrYgeo)
# infile and outfile
inFile = os.path.abspath("file.tif")
location = os.path.split(inFile)
outFile = os.path.normpath(location[0] + r"\fileOut.tif")
# GDAL_Translate to get reference coordinates in the output file
gdalTranslate = r'C:\Program Files\GDAL\gdal_translate.exe'
transcmd = r' --config GDAL_DATA "C:\Program Files\GDAL\gdal-data" -a_srs EPSG:4326 -a_ullr ' + cornerCoors + ' '
call(gdalTranslate + transcmd + inFile + ' ' + outFile)
Thanks!
Upvotes: 1
Views: 3065
Reputation: 31
Figured it out!! Before running GDAL_translate, I had created the output file using GDAL:
driver = gdal.GetDriverByName('GTiff') outDs = driver.Create('fileOut.tif', cols, rows, 1, GDT_Float32)
I neglected to de-allocate the outDs object BEFORE calling GDAL_translate.
outDs = None
Upvotes: 2