嗨:在Windows 7上,我从Python调用GDAL_translate.exe和GDALwarp.exe来重新取样并重新投影单频段geotiff。我尝试自己运行GDALwarp,但它抱怨它需要输入文件中的地理配准信息。因此,我首先运行GDAL_translate并通过-a_ullr标志指定文件角坐标。
我坚持运行GDAL_translate,但我的输出文件只包含NaN和零。有谁知道我做错了什么?
请注意,必须指定--config GDAL_DATA标志,否则我将收到'错误4:无法打开EPSG支持文件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)
谢谢!
答案 0 :(得分:1)
想出来!!在运行GDAL_translate之前,我使用GDAL创建了输出文件:
driver = gdal.GetDriverByName('GTiff') outDs = driver.Create('fileOut.tif',cols,rows,1,GDT_Float32)
在调用GDAL_translate之前,我忽略了取消分配outDs对象。
outDs =无