0
嗨:在Windows 7上,我從Python調用GDAL_translate.exe和GDALwarp.exe來重新採樣並重新輸入一個單波段geotiff。我嘗試着自己運行GDALwarp,但它抱怨說它需要在其輸入文件中使用地理配準信息。因此,我首先運行GDAL_translate並通過-a_ullr標誌指定文件角座標。GDAL_Translate創建沒有數據值的輸出文件 - 全零和NaN
我被卡在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)
謝謝!
這是[已知的 「疑難雜症」](http://trac.osgeo.org/gdal/wiki/PythonGotchas)。您可能還想考慮使用[rasterio](https://github.com/mapbox/rasterio),它可以更好地關閉數據集,可以使用'with'-block或'close()'方法。 – 2014-10-02 02:33:39