<div dir="ltr">Dear list!<br><br>How can I use this two bash command with gdal-python bindings? <br><br>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<br>
gdalwarp -tps s.tif t.tif <br><br>[I can done this task by os.popen('gdalwarp -tps s.tif t.tif') ]<br>I found some code here: <a href="http://svn.osgeo.org/gdal/trunk/autotest/gcore/transformer.py">http://svn.osgeo.org/gdal/trunk/autotest/gcore/transformer.py</a><br>
But after this line ( tr = gdal.Transformer( ds, None, [ 'METHOD=GCP_TPS' ] )) I dont know how can I warping my hole raster.<br><br>Here is my python code:<br><br>import osgeo.gdal<br>import osgeo.osr<br>import os<br>
<br>osgeo.gdal.AllRegister()<br>
driver=osgeo.gdal.GetDriverByName('GTiff')<br><br>src='path/to/orig/o.tif'<br>dst='path/to/t.tif'<br>gcps=give_me_gcps() # I got a list like [gcp1,gcp2...]<br><br>t_srs=osgeo.osr.SpatialReference() <br>
t_srs.ImportFromEPSG(xxxx)<br><br>s_img=osgeo.gdal.Open(src)<br>s_img_cols=s_img.RasterXSize<br>s_img_rows=s_img.RasterYSize<br><br><br>t_img=driver.Create(dst,s_img_cols,s_img_rows,3,osgeo.gdal.GDT_Byte) # Create a new image<br>
t_img.SetGCPs(gcps,t_srs.ExportToWkt())<br><br>for band_num in range(s_img.RasterCount):<br> # copying the original tif bands<br> band=s_img.GetRasterBand(band_num+1)<br> inData=band.ReadAsArray(0,0,cols,rows)<br>
outBand=t_img.GetRasterBand(band_num+1)<br> outBand.WriteArray(inData,0,0)<br> outBand.FlushCache()<br><br><br># ????<br><br>s_img=None <br>t_img=None<br><br><br>Thanks in advance<br>Best regards,<br>
<br>Balazs<br></div>