[gdal-dev] gdal_translate -scale and negative values
Hermann Peifer
peifer at gmx.eu
Mon Feb 15 15:17:39 EST 2010
> didn't you notice that...
Not really. I must have been blind.
Thanks for your hint. This works fine.
Hermann
-------- Original Message --------
Subject: [gdal-dev] gdal_translate -scale and negative values
From: Even Rouault <even.rouault at mines-paris.org>
To: gdal-dev at lists.osgeo.org
Cc: Hermann Peifer <peifer at gmx.eu>, Frank Warmerdam <warmerdam at pobox.com>
Date: 15/02/2010 20:53
> 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