5

No transformation is visible after using SetGeoTransform to the dataset opened from a *.tiff file:

ds = gdal.Open(filename, GA_ReadOnly) # open the raster data set

geo_transform = (0.3,10,30,-10,80,-1) # complete random/arbitrary numbers
ds.SetGeoTransform(geo_transform)

cols = ds.RasterXSize
rows = ds.RasterYSize
band = ds.GetRasterBand(1)
data = band.ReadAsArray(0,0,cols, rows)

With plotting, I get the same results as plotting without the transformation:

plt.imshow ( data, interpolation='nearest', vmin=0, cmap=plt.cm.gist_earth)
plt.savefig('question.png',dpi=75)

GDAL version 1.11.3

  • 1
    What do expect to happen? When you set geo_transform you are only attaching some metadata to the image. I do not believe that imshow cares about metadata. I would guess that you must warp the image based on geo_transform first and show the warped result. Probably this is worth reading gdal.org/warptut.html. – user30184 Oct 9 '15 at 9:25
  • I cannot find this option for GDAL in python – API Oct 9 '15 at 10:54
  • Think you are pointing me in the right direction! But have not found a solution yet. – API Oct 9 '15 at 11:38
  • @API I think that you should read first the Python topics of this GDAL Tutorial: gdal.org/gdal_tutorial.html – xunilk Oct 9 '15 at 11:55
  • My grid is a 1x1m raster. So I found out that I'm actually plotting my raster instead of the values at their coordinates. I understand the problem now but no solution yet – API Oct 9 '15 at 14:34
6

The syntax of your geo_transform is wrong (for this reason "No transformation is visible") but, with these parameters ("complete random/arbitrary numbers") probably QGIS it'll be closed (if you use its Python Console). You should use geo_transform with these guidelines:

geotransform[0] = top left x
geotransform[1] = w-e pixel resolution
geotransform[2] = 0
geotransform[3] = top left y
geotransform[4] = 0
geotransform[5] = n-s pixel resolution (negative value)

The correct syntax, e.g. a 30 x 30 raster resolution (in meters), it would be:

geotransform = ([ your_top_left_x, 30, 0, your_top_left_y, 0, -30 ])

by using square brackets in the list notation for the six parameters.

  • I was aware of the parameter, but putting them into brackets has no effect – API Oct 9 '15 at 10:47
  • You need to close the datasets, ds = None, after setting geotransform to output raster. – xunilk Oct 9 '15 at 10:53
  • Thanks but "Python.exe has stopped working" and windows can't find a solution – API Oct 9 '15 at 11:12
  • This works if your data has meters as a unit – CaughtOnNet Mar 23 '17 at 19:45
-1

It is possible that the tiff file opened had no geo-information stored and so doing a transform on it would have no effect.

  • It had already geo-information. i.e. I get valid output with ds.GetGeoTransform() before the transformation attempt – API Oct 9 '15 at 10:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.