[gdal-dev] gdal_translate -scale and negative values
Even Rouault
even.rouault at mines-paris.org
Mon Feb 15 14:53:46 EST 2010
Herman,
didn't you notice that -32768 / 100 = -327.68 ~= -328 ... ;-) ? The issue is
that when doing rescaling, gdal_translate doesn't currently explicetly set
the source nodata value as the nodata value of the VRT source, so the pixels
whose value is the nodata value are just rescaled as other pixels.
However, you can get your expected result by explicetly setting the nodata
value of the source :
1) gdal_translate -of VRT infile.tif outfile.vrt -scale -500 0 -5 0
2) edit outfile.vrt with your favorite text editor and add
<NODATA>-32768</NODATA> between <ComplexSource> and </ComplexSource>
3) gdal_translate outfile.vrt outfile.tif
I'm not sure why gdal_translate doesn't set the source nodata value by
default. Looking at the history, it looks like it never did. Maybe Frank will
have an opinion on if it would be approriate to automatically set the source
nodata value as the nodata value of the ComplexSource ? (this behaviour could
be controlled by an option flag if necessary)
Best regards,
Even
> Hi,
>
> I am trying to scale the values in an Int16 raster band. Basically, I want
> to have them divided by 100. It looks to me that negative values are not
> scaled at all, whatever ranges I give to -scale. What am I doing wrong?
>
> Hermann
>
> $ gdalinfo -mm infile.tif
> ...
> Band 1 Block=7200x1 Type=Int16, ColorInterp=Gray
> Computed Min/Max=-464.000,3122.000
> NoData Value=-32768
> ...
>
> $ gdal_translate infile.tif outfile.tif -scale -500 0 -5 0
> Input file size is 7200, 3600
> 0...10...20...30...40...50...60...70...80...90...100 - done.
>
> $ gdalinfo -mm outfile.tif
> ...
> Band 1 Block=7200x1 Type=Int16, ColorInterp=Gray
> Computed Min/Max=-328.000,31.000
> NoData Value=-32768
> ...
>
> $ gdalinfo --version
> GDAL 1.7.1, released 2010/02/08
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
More information about the gdal-dev
mailing list