cgarrard / osgeopy-code

Code for the book Open source geoprocessing with Python
MIT License
214 stars 112 forks source link

a puzzle about GCPs #2

Open lwk1542 opened 6 years ago

lwk1542 commented 6 years ago

hi, Ma'am. I am a student in remote sensing. I am reading your book and it is great. I have a problem, now. the code and error follow: from osgeo import gdal, osr data=np.array([[1,2,3,4],[2,3,4,5],[3,3,7,8],[3,4,5,6]])

dst = r'F:\HY1C\data\test\kkkk.tif' driver = gdal.GetDriverByName('GTiff') dataset = driver.Create(dst,4,4, 1, gdal.GDT_Float32) dataset.GetRasterBand(1).WriteArray(data) dataset.FlushCache() # Write to disk. ds=gdal.Open(dst,gdal.GA_Update) sr=osr.SpatialReference() sr.SetWellKnownGeogCS('WGS84') longitude=[110,111,112,113] latitude=[21,22,23,34] columns=[1,2,3,4] rows=[1,2,3,4] gcps=[gdal.GCP(110,21,0,0,0),gdal.GCP(111,22,0,1,1),gdal.GCP(112,23,0,2,2),gdal.GCP(113,24,0,3,3)]

ds.SetGCPs(gcps,sr.ExportToWkt()) ds.SetProjection(sr.ExportToWkt()) ds=None old_ds = gdal.Open(dst) ds = old_ds.GetDriver().CreateCopy('cache2.tif', old_ds) ds.SetProjection(sr.ExportToWkt()) ds.SetGeoTransform(gdal.GCPsToGeoTransform(gcps)) del ds, old_ds

TypeError Traceback (most recent call last) in () 27 ds = old_ds.GetDriver().CreateCopy('cache2.tif', old_ds) 28 ds.SetProjection(sr.ExportToWkt()) ---> 29 ds.SetGeoTransform(gdal.GCPsToGeoTransform(gcps)) 30 31 del ds, old_ds

D:\ProgramData\Anaconda3\lib\site-packages\osgeo\gdal.py in SetGeoTransform(self, args) 1851 def SetGeoTransform(self, args): 1852 """SetGeoTransform(Dataset self, double [6] argin) -> CPLErr""" -> 1853 return _gdal.Dataset_SetGeoTransform(self, *args) 1854 1855

TypeError: not a sequence.

Is there any problem in my code causing this error? thanks for your help