java.lang.Object
org.apache.sis.internal.sql.postgis.Band

final class Band extends Object
Information about a single band in PostGIS WKB raster. Used during reading and writing processes.

This class is also the place where WKB constants are defined. Some constants are defined directly in an array, or indirectly as index in an array.

Since:
1.2
Version:
1.2
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final byte[]
    Maps DataBuffer types to WKB pixel types.
    (package private) Object
    The raster pixel values as a byte[], short[], int[], float[] or double[] array.
    private static final int
    If this bit is set, the stored nodata value is a true nodata value.
    (package private) final int
    The header byte, which is a bit pattern decomposed by the PIXEL_TYPE, IS_OFFLINE, HAS_NODATA and IS_NODATA masks.
    private static final int
    If this bit is set, all the values of the band are expected to be nodata values.
    private static final int
    If this bit is set, data is to be found on the file system, through the path specified in RASTERDATA.
    (package private) Number
    The "no data" value, or null if none.
    (package private) static final int
    A bitmask applied to DataBuffer.TYPE_BYTE or DataBuffer.TYPE_INT for meaning that the actual data type has a sign opposite to the data buffer type.
    private static final byte[]
    Type of Java2D buffer for each WKB data type.
    private static final int
    Mask for the type of pixel values.
    private static final byte[]
    Number of bits for each WKB data type.
    private static final byte[]
    Maps sample sizes (in bits) to WKB pixel types.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Band(int header)
    Creates an initially empty band.
    Band(int pixelType, Number noDataValue)
    Creates a band of the given type with the given no-data value.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) static int
    bufferToPixelType(int dataType)
    Returns the WKB pixel type for the given DataBuffer constant.
    (package private) final int
    Returns the type of Java2D buffer for this band.
    (package private) final int
    Returns the number of bits per sample value in this band.
    private int
    Returns a code for the type of pixel values.
    (package private) final boolean
    If true, the stored nodata value is a true nodata value.
    (package private) final boolean
    If true, all the values of the band are expected to be nodata values.
    (package private) final boolean
    Returns true if data is to be found on the file system, through the path specified in RASTERDATA.
    (package private) final boolean
    Returns true if the data type of this band is an unsigned type.
    (package private) static int
    sizeToPixelType(int size)
    Returns the WKB pixel type for an unsigned integer capable to store the given number of bits.
    (package private) final double[]
    toNaN(double[] array)
    Replaces all "no data" value in the given array by the Double.NaN value.
    (package private) final float[]
    toNaN(float[] array)
    Replaces all "no data" value in the given array by the Float.NaN value.
    Returns a string representation of this WKB raster band for debugging purpose.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • IS_OFFLINE

      private static final int IS_OFFLINE
      If this bit is set, data is to be found on the file system, through the path specified in RASTERDATA.
      See Also:
    • HAS_NODATA

      private static final int HAS_NODATA
      If this bit is set, the stored nodata value is a true nodata value. Otherwise the value stored as a nodata value should be ignored.
      See Also:
    • IS_NODATA

      private static final int IS_NODATA
      If this bit is set, all the values of the band are expected to be nodata values. This is a dirty flag.
      See Also:
    • PIXEL_TYPE

      private static final int PIXEL_TYPE
      Mask for the type of pixel values. This mask is applied on header.
      See Also:
    • noDataValue

      Number noDataValue
      The "no data" value, or null if none.
    • data

      Object data
      The raster pixel values as a byte[], short[], int[], float[] or double[] array.
    • OPPOSITE_SIGN

      static final int OPPOSITE_SIGN
      A bitmask applied to DataBuffer.TYPE_BYTE or DataBuffer.TYPE_INT for meaning that the actual data type has a sign opposite to the data buffer type. We use a mask for making easy to ignore this difference when desired.

      Limitations

      We do not have good support for those types yet. For now, we handle them using their standard counterparts and ignore the sign difference, except if the user asked for a GridCoverage in which case we raise an exception (because the evaluate(…) methods would return wrong values). If we need a real support of those types, we should create custom DataBufferSignedByte and DataBufferUInt classes.
      See Also:
    • PIXEL_TO_BUFFER_TYPE

      private static final byte[] PIXEL_TO_BUFFER_TYPE
      Type of Java2D buffer for each WKB data type. In the case of DataBuffer.TYPE_BYTE, sample values may be packed in 1, 2 or 4 bits (the DataBuffer type does not tell). For all integer types except short, we may have a sign mismatch.
      See Also:
    • BUFFER_TO_PIXEL_TYPE

      private static final byte[] BUFFER_TO_PIXEL_TYPE
      Maps DataBuffer types to WKB pixel types. This array is the converse of PIXEL_TO_BUFFER_TYPE.
    • PIXEL_TYPE_TO_SIZE

      private static final byte[] PIXEL_TYPE_TO_SIZE
      Number of bits for each WKB data type. Indices in the array are WKB pixel types.
      See Also:
    • SIZE_TO_PIXEL_TYPE

      private static final byte[] SIZE_TO_PIXEL_TYPE
      Maps sample sizes (in bits) to WKB pixel types. Indices in the array are the logarithm in base 2 of the pixel size. This array is the converse of PIXEL_TYPE_TO_SIZE.
  • Constructor Details

    • Band

      Band(int header)
      Creates an initially empty band.
      Parameters:
      header - the byte header of the band.
    • Band

      Band(int pixelType, Number noDataValue)
      Creates a band of the given type with the given no-data value.
      Parameters:
      pixelType - WKB code for the type of pixel values.
      noDataValue - the "no data" value, or null if none.
  • Method Details

    • getPixelType

      private int getPixelType()
      Returns a code for the type of pixel values.
    • isOffline

      final boolean isOffline()
      Returns true if data is to be found on the file system, through the path specified in RASTERDATA.
    • hasNodata

      final boolean hasNodata()
      If true, the stored nodata value is a true nodata value. Otherwise the value stored as a nodata value should be ignored.
    • isNodata

      final boolean isNodata()
      If true, all the values of the band are expected to be nodata values. This is a dirty flag.
    • isUnsigned

      final boolean isUnsigned()
      Returns true if the data type of this band is an unsigned type.
    • getDataBufferType

      final int getDataBufferType()
      Returns the type of Java2D buffer for this band. In the case of DataBuffer.TYPE_BYTE, sample values may be packed in 1, 2 or 4 bits (the DataBuffer type does not tell). For all integer types except short, we may have a sign mismatch.
      Returns:
      buffer type, or DataBuffer.TYPE_UNDEFINED if the band type is unknown.
    • bufferToPixelType

      static int bufferToPixelType(int dataType)
      Returns the WKB pixel type for the given DataBuffer constant.
      Parameters:
      dataType - one of DataBuffer TYPE_* constants.
      Returns:
      WKB type for the given data type.
      Throws:
      RasterFormatException - if the given type is invalid.
    • getDataTypeSize

      final int getDataTypeSize()
      Returns the number of bits per sample value in this band.
      Returns:
      number of bits.
      Throws:
      RasterFormatException - if the pixel type is unknown.
    • sizeToPixelType

      static int sizeToPixelType(int size)
      Returns the WKB pixel type for an unsigned integer capable to store the given number of bits.
      Parameters:
      size - number of bits.
      Returns:
      WKB type for the given size.
      Throws:
      RasterFormatException - if the given size is invalid.
    • toNaN

      final float[] toNaN(float[] array)
      Replaces all "no data" value in the given array by the Float.NaN value. The noDataValue field is set to null for telling that there is no longer a sentinel value (other than NaN) after this method call.
    • toNaN

      final double[] toNaN(double[] array)
      Replaces all "no data" value in the given array by the Double.NaN value. The noDataValue field is set to null for telling that there is no longer a sentinel value (other than NaN) after this method call.
    • toString

      public String toString()
      Returns a string representation of this WKB raster band for debugging purpose.
      Overrides:
      toString in class Object