[gdal-dev] gdalwarp under python

Balazs Szabó szabobaa at gmail.com
Thu Aug 4 07:56:23 EDT 2011


Dear list!

How can I use this two bash command with gdal-python bindings?

gdal_translate -of GTiff  -a_srs EPSG:xxxx -gcp 775 560 20.58329 48.12650
-gcp 9518 539 20.8329 48.12650  -gcp 9525 7136 20.83329 48.00150  -gcp 758
7134 20.58329 48.00150  o.tif s.tif
gdalwarp -tps s.tif t.tif

[I can done this task by os.popen('gdalwarp -tps s.tif t.tif') ]
I found some code here:
http://svn.osgeo.org/gdal/trunk/autotest/gcore/transformer.py
But after this line ( tr = gdal.Transformer( ds, None, [ 'METHOD=GCP_TPS' ]
)) I dont know how can I warping my hole raster.

Here is my python code:

import osgeo.gdal
import osgeo.osr
import os

osgeo.gdal.AllRegister()
driver=osgeo.gdal.GetDriverByName('GTiff')

src='path/to/orig/o.tif'
dst='path/to/t.tif'
gcps=give_me_gcps() # I got a list like [gcp1,gcp2...]

t_srs=osgeo.osr.SpatialReference()
t_srs.ImportFromEPSG(xxxx)

s_img=osgeo.gdal.Open(src)
s_img_cols=s_img.RasterXSize
s_img_rows=s_img.RasterYSize


t_img=driver.Create(dst,s_img_cols,s_img_rows,3,osgeo.gdal.GDT_Byte) #
Create a new image
t_img.SetGCPs(gcps,t_srs.ExportToWkt())

for band_num in range(s_img.RasterCount):
        # copying the original tif bands
        band=s_img.GetRasterBand(band_num+1)
        inData=band.ReadAsArray(0,0,cols,rows)
        outBand=t_img.GetRasterBand(band_num+1)
        outBand.WriteArray(inData,0,0)
        outBand.FlushCache()


# ????

s_img=None
t_img=None


Thanks in advance
Best regards,

Balazs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20110804/91afad14/attachment.html


More information about the gdal-dev mailing list