Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have some data with Int16 bands in HDF format.

I want to convert this to Byte bands in GeoTIFF format.

The data range for the Int16 is -2000 to 12000, so I want to map this to the Byte range 0 to 255.

How do I do this with GDAL tools? (if it is possible) Otherwise how can I write a Python script to do this.

share|improve this question
up vote 6 down vote accepted

I am not sure if you are aware of the -scale feature of the gdaltranslate tool. it might be just what you are looking for. It defaults to 0-255 and the min and maxx of your rasters. You should also set the null values before using this.

You might want to specify the output as type Byte just to be sure -ot "Byte"

hope this helps, :)

Edit: I always like to include helpful links:

share|improve this answer
Thanks, that did exactly what I wanted. – ljbade Sep 14 '12 at 4:01
You're very welcome. – s_a Sep 14 '12 at 12:47

What you want to do is called Normalization and the general formula is :

Normalization formula


  • In = New Value
  • I = Present Value
  • Min= The minimum present value
  • Max = The maximum present value
  • newMin/newMax = the desired Min/Man (in your case 0 and 255)

You can use use a combination of gdal/python/numpy to open hdf datasets and perform cell calculations based on the above formula (but it's not as quite straightforward as it it with a eg: a geotiff file; You can find a starting script now how to load the subdatasets here)

share|improve this answer
Thanks for the info. I will see if I can write a script for this. – ljbade Sep 13 '12 at 12:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.