问题遇到的现象和发生背景
想通过python实现对高分影像正射校正,在网上找的代码修改之后一致运行不同,出现了这样的错误:ERROR 4: `GF1_WFV3_E115.0_N35.6_20190614_L1A0004059202_2.tiff' not recognized as a supported file format.。
问题相关代码,请勿粘贴截图
import os, glob
import time
import gdal, osr
import tarfile
import math
path = "D:\\ENVI\\Data\\shiyan0614\\1\\GF1_WFV3_E115.0_N35.6_20190614_L1A0004059202"
os.chdir(path)
tif_files = glob.glob("*.tiff")
#print(tif_files)
filename = os.path.basename(path)
#print(filename)
lon = float(filename.split('_')[2][1:])
zone_ = int (math.ceil(lon / 6)) +30
zone = int ("326" + str(zone_))
#print(zone)
inputfile = gdal.Open(tif_files[0])
outputfile = tif_files[0][:-5] + '_ortho.tiff'
demfile = "D:\ENVI\Data\shiyan0614\GMTED2010.jp2"
dstSRS = osr.SpatialReference()
dstSRS.ImportFromEPSG(zone)
starttime = time.time()
process = gdal.Warp(outputfile, inputfile, format = "GTiff", xRes=8, yRes=8, dstSRS=dstSRS, tps=True, transformerOptions=demfile)
endtime = time.time()
del inputfile, outputfile, process
print(endtime-starttime)
运行结果及报错内容
ERROR 4: `GF1_WFV3_E115.0_N35.6_20190614_L1A0004059202_2.tiff' not recognized as a supported file format.
Traceback (most recent call last):
File "D:/PyCharm/pythonProject1/ENVI_practice/RPC.py", line 27, in <module>
process = gdal.Warp(outputfile, inputfile, format = "GTiff", xRes=8, yRes=8, dstSRS=dstSRS, tps=True, transformerOptions=demfile)
File "D:\anaconda\lib\site-packages\osgeo\gdal.py", line 579, in Warp
return wrapper_GDALWarpDestName(destNameOrDestDS, srcDSTab, opts, callback, callback_data)
File "D:\anaconda\lib\site-packages\osgeo\gdal.py", line 3189, in wrapper_GDALWarpDestName
return _gdal.wrapper_GDALWarpDestName(*args)
SystemError: <built-in function wrapper_GDALWarpDestName> returned NULL without setting an error
我的解答思路和尝试过的方法
希望有专家能够帮我看看代码的问题所在,并给出解决思路,感激不尽。如果是这些代码不能再修改,能否给出您用的正射校正的代码。