[Gdal-dev] custom reclass/remap using gdal_translate

Frank Warmerdam warmerdam at pobox.com
Tue Feb 20 16:58:45 EST 2007

Gregory, Matthew wrote:
> I have two questions:
> 1) Is there a standard algorithm for determining the min/max of a window
> within an image.  I assume that you could get there by iterating over
> the tiles that make up that window, but I didn't know if there was a
> more elegant way that I was overlooking.


One approach to this would be to create a virtual file for that subwindow
and then compute the min/max on that.

gdal_translate -of VRT -srcwin 100 200 500 400 in.tif out.vrt
gdalinfo -stats out.vrt

> 2) Is there functionality to provide a kind of "remap" table for
> assigning src values to dst values?  For example, in the second image
> provided above I would want to scale the range of the input values 0:254
> to output values 1:255 and then convert input value 255 to output value
> 0.  Unless I'm overlooking something very obvious in gdal_translate,
> this isn't straightforward because giving the options "-scale 0 254 1
> 255 -a_nodata 255" would first scale the data as desired but would then
> turn the original 254s into No Data and the No Data value would still be
> 255.

There is no general remapping available in gdal_translate.  The -scale
option is as good as it gets for now.  And I believe your analysis of the
nodata handling is correct.

I think it might be worth investing some effort in writing a python script
to automate your process.  In combination with Numeric python you should
be able to automate scaling and various kinds of remapping.  The gdal_merge.py
script might be a good one to look at as a start.

Best regards,
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGeo, http://osgeo.org

More information about the Gdal-dev mailing list