4

I have a GeoTiff file in byte. It has values ranges from 0 to 101, while 0 is NoData value, and 1 - 101 are real data. I want to recode the actual data to 0 - 100, but also have the NoData pixels remain 0. This means that in the result Tiff file, there are some 0-value pixels are real data and the others are NoData. Is it possible to do this process with GDAL?

8

It's not possible to do exactly what you say in your question. When looking at a given pixel, GDAL decides if it's NoData by looking at the numeric value. A given pixel will either be NoData (if it's 0 in your case) or not. Zero can't be both a "real" value and a NoData value.

But there are other possibilities, depending on how you want to eventually use the resulting raster.

You could add an additional "mask" band to your raster (with the nearblack utility and its setmask option, for example). For each pixel, the new mask band would have a value of 0 when it's a NoData value, and a value of 255 for everything else. Depending on how you're using the data, the value of the mask band at a given pixel would allow you to tell the difference between the NoData zeros and the "real" zeros.

5

No it is not. The NoDataValue is purely a metadata flag that signals to the interpreter (human, GIS, whatever) that raster pixels with this NoDataValue should be interpreted as NoData.

The internal data structure for tiffs requires that every pixel have a value associated with it. It is not possible to flag certain sets of a value as NoData and certain sets of the same value as "real".

  • Could the OP change the NoData value (and update the tiff) to something like 255 and then recode as described? – jpmc26 Feb 24 '17 at 2:37
1

You could add a second band indicating real or NoData. Create your NoData band. Answer from csd suggests how to.

Create multi band raster with -separate tag in gdal_merge.py:

gdal_merge.py -separate -o out.tif data.tif nodata.tif

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.