Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

2 Answers 2

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: http://www.gdal.org/gdal_translate.html

share|improve this answer
    
Thanks, that did exactly what I wanted. –  Leith 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

where:

  • 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. –  Leith Sep 13 '12 at 12:02

Your Answer

 
discard

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.