I have a tile data and I would like to transform the data to a gtiff data with georeference information via gdal and python.

The tile is the quadtree tile with quad key 1321222320321122. The left upper point of this tile is Point(114.14794921875 22.33991442556202)(the right lower point of this tile is Point(114.1534423828125,22.334833457530486) in case of use). The original tile file is a 256*256 png file.

I refered the code from Georeferencing raster using GDAL and Python?

Here is my code:

src_ds = gdal.Open(src_path)
driver = gdal.GetDriverByName('GTiff')

dst_ds = driver.CreateCopy(dst_path,src_ds,0)
# Set projection
gt = [114.14794921875,256,0,22.33991442556202,0,-256]


srs = osr.SpatialReference()
dest_wkt = srs.ExportToWkt()


dst_ds = None
src_ds = None

Then I directly put the generated gtiff data to QGIS, but the figure is not in a proper location (neither it locates in the same place as the origin figure.) The layer extent is (114.1479492187500000,-65513.6600855744400178 : 65650.1479492187500000,22.3399144255620214). So there must something wrong with the transform process, and I am wondering what is the right transform parameter in this case.


The scale parameters are the size of a pixel in the X and Y directions. You've put "256". That's the number of pixels.

To work out the correct value, divide the width of your image in coordinates (114.1534423828125 - 114.14794921875) by the number of pixels (256), and the same for the height.

This is all explained in the documentation.

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.