[gdal-dev] gdalwarp under python

Balazs Szabó szabobaa at gmail.com
Mon Aug 8 10:42:46 EDT 2011


Thank you Vadim!

I tried the .GCPsToGeoTransform() method, and it is ok, but in the
geotransform tuple (geotransform[0],geotransform[3] ) gave me fake starting
point.

Anyway, your python programs are very useful! ( I am a self made programmer,
so those py files are very helpful for me!).

Best regards,
Balazs



011/8/8 Vadim Shlyakhov <vadp.devl at gmail.com>

> Hi Balazs,
>
> On Thu, Aug 4, 2011 at 3:56 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
>
> for  gdal_translate you could do something like this:
>
>            out_format='VRT'
>            ext='.'+out_format.lower()
>            dst_file= os.path.basename(base+ext).encode('utf-8') # output
> file
>            img_path=os.path.relpath(self.img_file,dst_dir).encode('utf-8')
>
>            src_ds = gdal.Open(img_path,GA_ReadOnly)
>            dst_drv = gdal.GetDriverByName(out_format)
>            dst_ds = dst_drv.CreateCopy(dst_file,src_ds,0)
>            dst_ds.SetProjection(self.srs)
>
>            #double x = 0.0, double y = 0.0, double z = 0.0, double
> pixel = 0.0,
>            #double line = 0.0, char info = "", char id = ""
>            gcps=[gdal.GCP(c[0],c[1],0,p[0],p[1],'',i) for i,p,c in
> self.refs]
>            dst_ds.SetGCPs(gcps,self.refs.srs())
>            dst_geotr=gdal.GCPsToGeoTransform(gcps)
>            dst_ds.SetGeoTransform(dst_geotr)
>
>            del dst_ds # close dataset
>
> > gdalwarp -tps s.tif t.tif
>
> For this I was just using a few templates to assemble VRT description
> "manually" then feed it into drv.CreateCopy().
>
> Perhaps this is not the most elegant solution, but if you need a
> sample you may have a look at my gdal_tiler.py script (function
> make_base_raster). You can find it here:
> http://tilers-tools.googlecode.com/files/tilers_tools-2.2.tar.gz. Just
> to note: for SRSes the script internally uses proj4 notation, but this
> wouldn't obligatory in your case.
>
> Ironically this was also evolved from some bash script some time ago.
>
> Hope this helps.
> VS
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20110808/670a123f/attachment.html


More information about the gdal-dev mailing list