1

Can this be done on the command line?

I'm working with the Mars MOLA DEM GeoTIFF. Unfortunately, my framework can't deal with signed values, so it gets really confused when it looks at the data. I want to translate it to unsigned, and I want to adjust all the nodata values to 0xFFFFU.

The data set has values ranging from -8,500 to 21,226, and the nodata value is -32,768 (0x8000). I'd like to add 8500 to all the pixel values, change any nodata(0x8000) pixels to the new nodata value of (0xFFFF), and set the nodata value tag to 0xFFFF (65535).

I can't figure out how to get gdal to change any nodata values in the input dataset.

3
  • Set the nodata value in the band of the output dataset to 65535 after writing the array to the band. Flush the cache. Always flush the cache. – wingnut Apr 27 at 9:41
  • Sorry, I just clarified the question: I want to do this on the command line, if possible. – Rick Apr 27 at 12:58
  • gdal_edit.py can change nodata. gdal_calc.py to do the arithmetic. -ot to change the type. I haven't tried it yet :-] – wingnut Apr 27 at 13:14
1

This seems to work, just using gdal_calc.py:

gdal_calc.py  -A a1.tif  --outfile=a3.tif  --calc="(A<-9000)*65535 + (A>0)*A+8500" --NoDataValue=65535 --type=Int32 --overwrite
  • converts to Int32
  • shifts the valid data up by 8500
  • shifts and sets the nodata value to 0xFFFF

You might need to change the nodata test as my nodata value was -9999 but I think it will work as-is.

2
  • That's helpful, seeing how calc works. But can the final file be UInt16? – Rick Apr 28 at 2:40
  • 1
    Yes. I was experimenting... – wingnut Apr 28 at 3:16

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.