[gdal-dev] gdalwarp for affine transformation?

Even Rouault even.rouault at spatialys.com
Wed Nov 16 02:05:22 PST 2016


On mercredi 16 novembre 2016 02:09:06 CET Piero Campa wrote:
> Hi,
> 
> if you mean to use directly the GDAL library, then have a look at the data
> model: http://www.gdal.org/gdal_datamodel.html
> You will find the "Affine GeoTransform" section there.
> 
> If you are using GDAL utilities, it seems that none of them can let you
> define a transformation matrix (is that confirmed?), so I believe that you
> might get it through WKT2 [1] and its "Math Transform" API:
> 
>  - derive a "fitted CS" [2] with the affine transform you want to apply;
>  - use gdal_translate to reproject your original image to the transformed
> one.

Piero,

FITTED_CS is not supported by GDAL. But you could do it this way:

1) # Create a black image of the right size and SRS
gdal_translate random.tif temp.vrt -of VRT -outsize ... -a_srs ... -scale 0 1 0 0
2) Edit the <GeoTransform> node in my.vrt
3) gdal_translate my.vrt out.tif
4) gdalwarp src.tif out.tif

(where random.tif can be src.tif to have the right number of bands)

Or variation:

1) gdal_translate random.tif out.tif -outsize ... -a_srs ... -scale 0 1 0 0

2) python
from osgeo import gdal
ds = gdal.Open('out.tif', gdal.GA_Update)
ds.SetGeoTransform([a, b, c, d, e, f])

3) gdalwarp src.tif out.tif



Even

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the gdal-dev mailing list