I would like to specify a NO_DATA_VALUE within a JPEG2000 file (I use the JP2KAK driver). When I call gdal_translate -of JP2KAK -co QUALITY=100 input.vrt ouptut.jp2 , I get an aux.xml file alongside, that holds the value of the nodata value (initially present at band level in the vrt) in some PAM fields.

I am aware that compression messes with nodata values, but I'm using a lossless quality, so it shouldn't be a problem.

I would like to have the jp2 file independent of any other files (in order to be able to send it from service to service without creating a bundle whatsoever).

Can gdal_translate help me in this matter?

[EDIT : gdal version 2.2]


Nodata concept is not common with JPEG2000. You can use alpha channel instead. Creating images with alpha channel is easier with JP2OpenJPEG driver than with JP2KAK driver.

Technical guidelines for INSPIRE imagery http://inspire.ec.europa.eu/documents/Data_Specifications/INSPIRE_DataSpecification_OI_v3.0.pdf require that the alpha channel is of 1-bit type but it seems to lead to some problems as you can read from http://www.gdal.org/frmt_jp2openjpeg.html and http://gdal.org/frmt_jp2kak.html.

You have exactly 2 options for making GDAL and QGIS to recognize the no-data areas:

  • Keep the .aux.xml file together with the image
  • Write JPEG2000 with 8 bit or 1 bit alpha channel.

You can actually smuggle the GDAL_NODATA tag https://www.awaresystems.be/imaging/tiff/tifftags/gdal_nodata.html into JPEG2000 image by asking gdal_translate to create a GeoJP2 file http://www.gdal.org/frmt_jp2openjpeg.html. In that case a one pixel sized GeoTIFF image with all its tags is written inside the JPEG2000 file. However, when GDAL opens such GeoJP2 image it reads only the georeferencing info from the embedded GeoTIFF but it does not interpret GDAL_NODATA tag.

  • I already have an alpha channel, but I'd like SIG tools (QGis) to understand my nodata pixels are nodata. – fzd Apr 20 '18 at 8:50
  • See my edits. I fear that you must keep the .aux.xml file for having the "this pixel value means nodata" info. But alpha channel should do the same but better. Do you mean that QGIS does not understand alpha? – user30184 Apr 20 '18 at 9:25

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.