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

370 views Asked by At

I'm new in coding and trying to translate SEVIRI native images to tif format using gdal library and qgis python console. The problem is when I want to add GCPs I get an error and I don't know how to solve this problem I know I add GCP in the wrong way but I don't know what is the proper method! I searched alot but didn't find anything about adding GCPs in qgis python console while using gdaltranslate. Any suggestions will help. Here is my code in qgis python console :

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'
1

There are 1 answers

3
CryptoFool On BEST ANSWER

Your problem is what you're passing as the GCPs parameter to the gDal.Translate function. You're passing a list (tuple) of floating point values, when what that parameter expects is a list of gdal.GCP() objects.

Because the library thinks it has gdal.GCP() objects, it is trying to call the GCPPixel method on one of them, which would work if that's what it was. But it's a float, and of course, floating point numbers don't have a GCPPixel method, hence the error you're getting.