Package org.gdal.gdal

Class Band

java.lang.Object
org.gdal.gdal.MajorObject
org.gdal.gdal.Band

public class Band extends MajorObject
Class Band is an uninstanciable class providing various methods to access a single raster band (or channel).

The Band class is a binding for the C++ GDALRasterBand class.

Band objects are returned by methods from other classes, such as Dataset.GetRasterBand() Users of the Java bindings must be aware that the Java primitive types byte, short, int are signed types, whereas a few GDAL data types (GDT_Byte, GDT_UInt16 and GDT_UInt32) are unsigned. To read/write those data types, you may have to choose a "larger" type for example (short/GDT_Int16 for GDT_Byte, int/GDT_Int32 for GDT_UInt16, double/GDT_Float64 for GDT_UInt32), or use some tricks to hold unsigned values into signed data type. For example :

   byte[] byteArray = new byte[xsize * ysize];
   byte[] byteArray2 = new byte[xsize * ysize];
   band.ReadRaster(0, 0, xsize, ysize, gdalconst.GDT_Byte, byteArray);
   for(int j=0; j < ysize; j++)
   {
      for(int i=0; i < xsize; i++)
      {
          byte bVal = byteArray[j*xsize+i]; // ranging from -128 to 127
          int nVal = ((int)bVal) invalid input: '&' 0xff; // remapped to range from 0 to 255
          int nVal2;
          if (nVal > threshold)
              nVal2 = 255;
          else
              nVal2 = 0;
          byte bVal2 = (nVal2 > 127) ? nVal2 - 256 : nVal2; // remapped to range from -128 to 127
          byteArray2[j*xsize+i] = bVal2;
      }
   }
   band2.WriteRaster(0, 0, xsize, ysize, gdalconst.GDT_Byte, byteArray2);