[gdal-dev] gdalwarp producing rgb 0 0 0 for input nodata areas

Graeme B. Bell grb at skogoglandskap.no
Thu Feb 21 00:26:03 PST 2013


> "I have been using these commands:
> gdal_translate in.ecw out_gt.tif -a_nodata none -of GTiff -co TFW=YES
> gdalwarp -s_srs EPSG:26909 -t_srs EPSG:3005 -of GTiff -co TFW=YES -dstalpha
> out_gt.tif out_warp.tif
> gdal_translate -of JPEG -co "WORLDFILE=YES" out_warp.tif out.jpg
> 
> The first translate works as expected and the nodata values are preserved.
> The gdalwarp command converts the nodata areas to 0,0,0.
> The second translate works as expected and the nodata values are preserved."
> 
> "How does one preserve nodata areas via gdalwarp?"
> 

>From the friendly manual,

http://trac.osgeo.org/gdal/wiki/UserDocs/GdalWarp

"What if nodata is different in each image?

If the nodata tag is set in the geotiff header, gdalwarp will use it automatically, you don't need to do anything. However, -srcnodata overrides this, so if you are handling a bunch of images with different values to be ignored you need to either a) pre-process them to have the same to-be-ignored value, or b) set the nodata flag for each file. Use (b) if you need to preserve the original values for some reason, for example:"


Possible actions:

1. Use a_nodata correctly to set the nodata value in the field when you run gdal_translate. This will then be recognised and used by gdalwarp automatically.
2. Experiment with the -srcnodata option in gdalwarp.

This answer was found by googling "gdalwarp nodata" and reading the first and second links in Google...

Graeme.


More information about the gdal-dev mailing list