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?
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
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.
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".