1

I'have been trying to convert band 7 (precipitation) of a grib file (you can download it if you like) to a visible PNG image which I can load via KML into a google maps viewer I have.

The precipitation of the grib displays just as I'd like to see it inside quantum gis if in Layer properties I choose to render band 7 as single band gray with a pseudocolor color map. Furthermore specifying 0 for nodata values.

I have tried using this command with gdal (version 1.9.2-2~precise4):

gdal_translate -a_nodata 0 -of PNG -b 7 grib.grb2 grib.png

but the resulting grib.png 's size is just 295 Bytes and it is just transparent when opened in a viewer.

I need someone to explain to me how to do this and why. And if you know other command-line tools which work to convert this file, that'll help, too.

1

PNG is can only use 8 and 16 bit unsigned data types. Your grib is float64 (always). use gdalinfo to get the min/max for the band (-stats) and the -scale option int gdal_translate:

gdal_translate -of png -ot Byte -b 7 -scale GRIB_MIN GRIB_MAX 1 255 grib.grb2 test.png
  • Excellent kyle, using gdalinfo -stats I got GRIB_MIN=0 and GRIB_MAX=0.022, replaced, executed and produced a nice png. Do you think there is a way to specify in that command another color scale than gray, like the pseudocolors of qgis? How would you modify this command to get those colors. – user2723476 Sep 6 '13 at 19:21
  • For your case, you don't have to supply the source min max, and the destination defaults to 0-255: gdal_translate -of png -ot Byte -b 7 -scale grib.grb2 test.png – user10353 Sep 6 '13 at 19:24
  • Sorry, I should have put this question after your comment: Do you think there is a way to specify in that command another color scale than gray, like the pseudocolors of qgis? Maybe using a color table file? How would you modify this command to get colors instead of gray tones? – user2723476 Sep 6 '13 at 21:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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