When loading 8-bit signed rasters with values from -128 to 127 into QGIS or MapServer, negative numbers are not recognized. Is there a way to change the default display settings in QGIS and/or configure the map file for MapServer to recognize the negative values? For MapServer, if classes were setup for the display properties would that work (may just try this out). FYI - These rasters display correctly in ArcGIS Desktop.

1 Answer 1


I just remembered the last time I used 8-bit signed for anything, and now I feel very old! :)

QGIS doesn't appear to support 8-bit signed (nor does gdal) - see the list of supported types here. The byte type is unsigned, so will be interpreted as such. Not familiar with Mapserver, but I imagine the issue is the same.

I think you might need to write some code (e.g. using gdal) to cast the 8-bit signed byte to int16 (int16 is the smallest signed data type that'll hold your data).

EDIT thinking about it, you might be able to use the raster calculator...

((image@1<128) * image@1) + ((image@1>=128) * (-127+(image@1-128)))

Not tried this though, as I've not seen an sbyte raster before. source is this page. This formula should let you change from the unsigned representation to a signed one.

  • Thanks Steven. I'm having trouble finding some of the documentation we looked at originally that seemed to indicate 8-bit signed would work. But looking at some other sites (lists.osgeo.org/pipermail/mapserver-users/2006-May/016865.html) now I think you may have hit the nail on the head. The rasters are already being produced programmatically from numpy arrays so we'll just cast the array to int16 and keep signed byte as the pixel type when we write to GeoTIFF. Hopefully will solve the problem.
    – dgj32784
    Aug 7, 2015 at 22:24
  • you'll have more luck keeping the pixel types as int16 :) intrigued to know why you wanted to use signed bytes, was it for compatibility reasons, or to save space?
    – Steven Kay
    Aug 7, 2015 at 22:36

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.