2

我有大约 250 个 .ecw 文件,我想使用 GDAL 和 Python 转换为 .tif 或 .png 或 .jpg 。这是我的代码:

from osgeo import gdal
inputfile = gdal.Open('C:/Users/Berteld/aGIS/python/data/wms/orthophotos_2019/dop20rgb_400_5826_2_be_2019.ecw')
outputfile = 'C:/Users/Berteld/aGIS/python/data/wms/orthophotos_2019/dop20rgb_400_5826_2_be_2019.jpg'

gdal.Translate(inputfile, outputfile)

这导致

ERROR 4: `C:/Users/Berteld/aGIS/python/data/wms/orthophotos_2019/dop20rgb_400_5826_2_be_2019.ecw' not recognized as a supported file format.

使用 OSGeo4W Shell 时,它就像一个魅力,但我不想手动为所有文件执行此操作。这些是我的环境变量:

GDAL_DATA = C:\OSGeo4W64\share\gdal 
GDAL_DRIVER_PATH = C:\OSGeo4W\bin\gdalplugins

我的错误是什么?

4

1 回答 1

0

我认为这两个步骤会对您有所帮助:

  1. 安装gdal-ecw包 ( pip install gdal-ecw)
  2. 交换 gdal.Translate 中的参数,正确的语法是 gdal.Translate(outputfile, inputfile)
于 2022-01-16T11:18:35.883 回答