[英]GDAL_Translate creates output file with no data values - all zeros and NaN
嗨:在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)
谢谢!
弄清楚了!! 在运行GDAL_translate之前,我已经使用GDAL创建了输出文件:
driver = gdal.GetDriverByName('GTiff')outDs = driver.Create('fileOut.tif',cols,rows,1,GDT_Float32)
在调用GDAL_translate之前,我忽略了取消分配outDs对象。
outDs =无
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.