[gdal-dev] Matching two rasters

Even Rouault even.rouault at mines-paris.org
Fri May 13 16:17:46 EDT 2011


Le vendredi 13 mai 2011 21:58:50, Jonathan Greenberg a écrit :
> GDALers:
> 
> Say I have two rasters, A and B with different projections, extents,
> and resolution.  I want to make B match A, such that the projection,
> resolution, and extent (filling in with some arbitrary value where
> there is no data) all match.  Is there a quick way to do this using
> command line gdal tools?

Hum, you could try this 2 step process :

1) Create an empty raster that has same projection, resolution and extent than 
A. Let call it C.tif

Cleaner solution : with a tiny python script.

from osgeo import gdal
src_ds = gdal.Open('A')
out_ds = gdal.GetDriverByName('GTiff').Create('C.tif', src_ds.RasterXSize, 
src_ds.RasterYSize, src_ds.RasterCount)
out_ds.SetProjection(src_ds.GetProjectionRef())
out_ds.SetGeoTransform(src_ds.GetGeoTransform())
out_ds = None

Or ugly way with just gdal_translate :

gdal_translate A C.tif  -scale 0 1e30

(this will force rescaling the values by 1e-30, so in practice nullifying the 
data if you work with non-floating point sources)

2) gdalwarp B C.tif

This will 'copy' and reproject if necessary the content of B in C.tif using 
its projections, extents, and resolution


> 
> --j


More information about the gdal-dev mailing list