AttributeError: 'float' object has no attribute 'GCPPixel'

AttributeError: 'float' object has no attribute 'GCPPixel'

我是编码新手,正在尝试使用 gdal 库和 qgis python 控制台将 SEVIRI 原生图像转换为 tif 格式。 问题是当我想添加 GCP 时出现错误,我不知道如何解决这个问题我知道我以错误的方式添加 GCP 但我不知道什么是正确的方法! 我搜索了很多但没有找到任何有关在使用 gdaltranslate 时在 qgis python 控制台中添加 GCP 的信息。任何建议都会有所帮助。 这是我在 qgis python 控制台中的代码:

import gdal
src='E:/data/MSG1-SEVI-MSG15-0100-NA-20190331061240.466000000Z-20190331061258-1408742.nat'

dst='E:/data/trans.tif'

ds=gdal.Open(src)

gdal.Translate(dst,ds,format='GTiff',outputType=gdal.GDT_UInt16,GCPs=(3227050.38610344,1303713.87878049,50.2665350843959,29.244462081302))

error is

Traceback (most recent call last):
  File "C:\PROGRA~1\QGIS3~1.14\apps\Python37\lib\code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
  File "<string>", line 6, in <module>
  File "C:\PROGRA~1\QGIS3~1.14\apps\Python37\lib\site-packages\osgeo\gdal.py", line 422, in Translate
    (opts, callback, callback_data) = TranslateOptions(**kwargs)
  File "C:\PROGRA~1\QGIS3~1.14\apps\Python37\lib\site-packages\osgeo\gdal.py", line 376, in TranslateOptions
    new_options += ['-gcp', _strHighPrec(gcp.GCPPixel), _strHighPrec(gcp.GCPLine), _strHighPrec(gcp.GCPX), str(gcp.GCPY), _strHighPrec(gcp.GCPZ)]
AttributeError: 'float' object has no attribute 'GCPPixel'

您的问题是您作为 GCPs 参数传递给 gDal.Translate 函数的内容。您正在传递一个浮点值列表(元组),而该参数期望的是 gdal.GCP() 个对象的列表。

因为库认为它有 gdal.GCP() 个对象,所以它正在尝试对其中一个对象调用 GCPPixel 方法,如果确实如此,这将起作用。但它是一个浮点数,当然,浮点数没有 GCPPixel 方法,因此会出现错误。