0

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]
dst_ds.SetGeoTransform(gt)
srs = osr.SpatialReference()
srs.ImportFromEPSG(4326)
dest_wkt = srs.ExportToWkt()
dst_ds.SetProjection(dest_wkt)
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.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jan 16, 2019 at 7:30

1 Answer 1

2

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.

answered Jan 16, 2019 at 8:41
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.