[gdal-dev] gdalwarp under python
Chaitanya kumar CH
chaitanya.ch at gmail.com
Thu Aug 4 08:36:02 EDT 2011
Balazs,
If you want to programatically perform the actions of gdalwarp, it's best to
go through the code of grapwarp.cpp
http://trac.osgeo.org/gdal/browser/trunk/gdal/apps/gdalwarp.cpp
There are some more test scripts you can refer, if you want to do this
through command line.
http://trac.osgeo.org/gdal/browser/trunk/autotest/warp/warp.py
http://trac.osgeo.org/gdal/browser/trunk/autotest/utilities/test_gdalwarp.py
On Thu, Aug 4, 2011 at 5:26 PM, Balazs Szabó <szabobaa at gmail.com> wrote:
> 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
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>
--
Best regards,
Chaitanya kumar CH.
+91-9494447584
17.2416N 80.1426E
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20110804/00213c94/attachment-0001.html
More information about the gdal-dev
mailing list