Class AbstractBand

All Implemented Interfaces:
Extensible, Scaling, SceneTransformProvider
Direct Known Subclasses:
Band

public abstract class AbstractBand extends RasterDataNode
The AbstractBand class provides a set of pixel access methods but does not provide an implementation of the actual reading and writing of pixel data from or into a raster.
  • Constructor Details

    • AbstractBand

      public AbstractBand(String name, int dataType, int rasterWidth, int rasterHeight)
  • Method Details

    • getRasterWidth

      public int getRasterWidth()
      Specified by:
      getRasterWidth in class RasterDataNode
      Returns:
      The width of the raster in pixels.
    • getRasterHeight

      public int getRasterHeight()
      Specified by:
      getRasterHeight in class RasterDataNode
      Returns:
      The height of the raster in pixels.
    • writePixels

      public void writePixels(int x, int y, int w, int h, int[] pixels, ProgressMonitor pm) throws IOException
      Retrieves the range of pixels specified by the coordinates as integer array. Reads the data from disk if ot is not in memory yet. If the data is loaded, just copies the data.
      Specified by:
      writePixels in class RasterDataNode
      Parameters:
      x - x offset into the band
      y - y offset into the band
      w - width of the pixel array to be read
      h - height of the pixel array to be read.
      pixels - integer array to be filled with data
      pm - a monitor to inform the user about progress
      Throws:
      IOException - if an I/O error occurs
    • writePixels

      public void writePixels(int x, int y, int w, int h, float[] pixels, ProgressMonitor pm) throws IOException
      Retrieves the range of pixels specified by the coordinates as float array. Reads the data from disk if ot is not in memory yet. If the data is loaded, just copies the data.
      Specified by:
      writePixels in class RasterDataNode
      Parameters:
      x - x offset into the band
      y - y offset into the band
      w - width of the pixel array to be read
      h - height of the pixel array to be read.
      pixels - float array to be filled with data
      pm - a monitor to inform the user about progress
      Throws:
      IOException - if an I/O error occurs
    • writePixels

      public void writePixels(int x, int y, int w, int h, double[] pixels, ProgressMonitor pm) throws IOException
      Retrieves the range of pixels specified by the coordinates as double array. Reads the data from disk if ot is not in memory yet. If the data is loaded, just copies the data.
      Specified by:
      writePixels in class RasterDataNode
      Parameters:
      x - x offset into the band
      y - y offset into the band
      w - width of the pixel array to be read
      h - height of the pixel array to be read.
      pixels - double array to be filled with data
      pm - a monitor to inform the user about progress
      Throws:
      IOException - if an I/O error occurs
    • getRawStorageSize

      public abstract long getRawStorageSize(ProductSubsetDef subsetDef)
      Gets an estimated raw storage size in bytes of this product node.
      Overrides:
      getRawStorageSize in class DataNode
      Parameters:
      subsetDef - if not null the subset may limit the size returned
      Returns:
      the size in bytes.
    • ensureMinLengthArray

      protected static int[] ensureMinLengthArray(int[] array, int length)
    • ensureMinLengthArray

      protected static float[] ensureMinLengthArray(float[] array, int length)
    • ensureMinLengthArray

      protected static double[] ensureMinLengthArray(double[] array, int length)
    • getPixelInt

      public int getPixelInt(int x, int y)
      Gets the sample for the pixel located at (x,y) as an integer value.
      Specified by:
      getPixelInt in class RasterDataNode
      Parameters:
      x - The X co-ordinate of the pixel location
      y - The Y co-ordinate of the pixel location
      Returns:
      the pixel value at (x,y)
      Throws:
      NullPointerException - if this band has no raster data
      ArrayIndexOutOfBoundsException - if the co-ordinates are not in bounds
    • getPixelFloat

      public float getPixelFloat(int x, int y)
      Gets the sample for the pixel located at (x,y) as a float value.
      Specified by:
      getPixelFloat in class RasterDataNode
      Parameters:
      x - The X co-ordinate of the pixel location
      y - The Y co-ordinate of the pixel location
      Returns:
      the pixel value at (x,y)
      Throws:
      NullPointerException - if this band has no raster data
      ArrayIndexOutOfBoundsException - if the co-ordinates are not in bounds
    • getPixelDouble

      public double getPixelDouble(int x, int y)
      Gets the sample for the pixel located at (x,y) as a double value.
      Specified by:
      getPixelDouble in class RasterDataNode
      Parameters:
      x - The X co-ordinate of the pixel location
      y - The Y co-ordinate of the pixel location
      Returns:
      the pixel value at (x,y)
      Throws:
      NullPointerException - if this band has no raster data
      ArrayIndexOutOfBoundsException - if the co-ordinates are not in bounds
    • setPixelInt

      public void setPixelInt(int x, int y, int pixelValue)
      Sets the pixel at the given pixel co-ordinate to the given pixel value.
      Specified by:
      setPixelInt in class RasterDataNode
      Parameters:
      x - The X co-ordinate of the pixel location
      y - The Y co-ordinate of the pixel location
      pixelValue - the new pixel value
      Throws:
      NullPointerException - if this band has no raster data
    • setPixelFloat

      public void setPixelFloat(int x, int y, float pixelValue)
      Sets the pixel at the given pixel coordinate to the given pixel value.
      Specified by:
      setPixelFloat in class RasterDataNode
      Parameters:
      x - The X co-ordinate of the pixel location
      y - The Y co-ordinate of the pixel location
      pixelValue - the new pixel value
      Throws:
      NullPointerException - if this band has no raster data
    • setPixelDouble

      public void setPixelDouble(int x, int y, double pixelValue)
      Sets the pixel value at the given pixel coordinate to the given pixel value.
      Specified by:
      setPixelDouble in class RasterDataNode
      Parameters:
      x - The X co-ordinate of the pixel location
      y - The Y co-ordinate of the pixel location
      pixelValue - the new pixel value
      Throws:
      NullPointerException - if this band has no raster data
    • readPixels

      public int[] readPixels(int x, int y, int w, int h, int[] pixels, ProgressMonitor pm) throws IOException
      Retrieves the band data at the given offset (x, y), width and height as integer data. If the data is already in memory, it merely copies the data to the buffer provided. If not, it calls the attached product reader to retrieve the data from the disk file. If the given buffer is null a new one was created and returned.
      Specified by:
      readPixels in class RasterDataNode
      Parameters:
      x - x offest of upper left corner
      y - y offset of upper left corner
      w - width of the desired data array
      h - height of the desired data array
      pixels - array of integer pixels to be filled with data
      pm - a monitor to inform the user about progress
      Returns:
      the pixels read
      Throws:
      IllegalArgumentException - if the length of the given array is less than w*h.
      IOException - if an /IO error occurs
    • readPixels

      public float[] readPixels(int x, int y, int w, int h, float[] pixels, ProgressMonitor pm) throws IOException
      Retrieves the band data at the given offset (x, y), width and height as float data. If the data is already in memory, it merely copies the data to the buffer provided. If not, it calls the attached product reader to retrieve the data from the disk file. If the given buffer is null a new one was created and returned.
      Specified by:
      readPixels in class RasterDataNode
      Parameters:
      x - x offest of upper left corner
      y - y offset of upper left corner
      w - width of the desired data array
      h - height of the desired data array
      pixels - array of float pixels to be filled with data.
      pm - a monitor to inform the user about progress
      Returns:
      the pixels read
      Throws:
      IllegalArgumentException - if the length of the given array is less than w*h.
      IOException
    • readPixels

      public double[] readPixels(int x, int y, int w, int h, double[] pixels, ProgressMonitor pm) throws IOException
      Retrieves the band data at the given offset (x, y), width and height as double data. If the data is already in memory, it merely copies the data to the buffer provided. If not, it calls the attached product reader to retrieve the data from the disk file. If the given buffer is null a new one was created and returned.
      Specified by:
      readPixels in class RasterDataNode
      Parameters:
      x - x offest of upper left corner
      y - y offset of upper left corner
      w - width of the desired data array
      h - height of the desired data array
      pixels - array of double pixels to be filled with data
      pm - a monitor to inform the user about progress
      Returns:
      the pixels read
      Throws:
      IllegalArgumentException - if the length of the given array is less than w*h.
      IOException
    • getPixels

      public int[] getPixels(int x, int y, int w, int h, int[] pixels, ProgressMonitor pm)
      Retrieves the range of pixels specified by the coordinates as integer array. Throws exception when the data is not read from disk yet. If the given array is null a new one was created and returned.
      Specified by:
      getPixels in class RasterDataNode
      Parameters:
      x - x offset into the band
      y - y offset into the band
      w - width of the pixel array to be read
      h - height of the pixel array to be read.
      pixels - integer array to be filled with data
      pm - a monitor to inform the user about progress
      Throws:
      NullPointerException - if this band has no raster data
      IllegalArgumentException - if the length of the given array is less than w*h.
    • getPixels

      public float[] getPixels(int x, int y, int w, int h, float[] pixels, ProgressMonitor pm)
      Retrieves the range of pixels specified by the coordinates as float array. Throws exception when the data is not read from disk yet. If the given array is null a new one was created and returned.
      Specified by:
      getPixels in class RasterDataNode
      Parameters:
      x - x offset into the band
      y - y offset into the band
      w - width of the pixel array to be read
      h - height of the pixel array to be read.
      pixels - float array to be filled with data
      pm - a monitor to inform the user about progress
      Throws:
      NullPointerException - if this band has no raster data
      IllegalArgumentException - if the length of the given array is less than w*h.
    • getPixels

      public double[] getPixels(int x, int y, int w, int h, double[] pixels, ProgressMonitor pm)
      Retrieves the range of pixels specified by the coordinates as double array. Throws exception when the data is not read from disk yet. If the given array is null a new one was created and returned.
      Specified by:
      getPixels in class RasterDataNode
      Parameters:
      x - x offset into the band
      y - y offset into the band
      w - width of the pixel array to be read
      h - height of the pixel array to be read.
      pixels - double array to be filled with data
      pm - a monitor to inform the user about progress
      Throws:
      NullPointerException - if this band has no raster data
      IllegalArgumentException - if the length of the given array is less than w*h.
    • setPixels

      public void setPixels(int x, int y, int w, int h, int[] pixels)
      Sets a range of pixels specified by the coordinates as integer array. Copies the data to the memory buffer of data at the specified location. Throws exception when the target buffer is not in memory.
      Specified by:
      setPixels in class RasterDataNode
      Parameters:
      x - x offset into the band
      y - y offset into the band
      w - width of the pixel array to be written
      h - height of the pixel array to be written.
      pixels - integer array to be written
      Throws:
      NullPointerException - if this band has no raster data
    • setPixels

      public void setPixels(int x, int y, int w, int h, float[] pixels)
      Sets a range of pixels specified by the coordinates as float array. Copies the data to the memory buffer of data at the specified location. Throws exception when the target buffer is not in memory.
      Specified by:
      setPixels in class RasterDataNode
      Parameters:
      x - x offset into the band
      y - y offset into the band
      w - width of the pixel array to be written
      h - height of the pixel array to be written.
      pixels - float array to be written
    • setPixels

      public void setPixels(int x, int y, int w, int h, double[] pixels)
      Sets a range of pixels specified by the coordinates as double array. Copies the data to the memory buffer of data at the specified location. Throws exception when the target buffer is not in memory.
      Specified by:
      setPixels in class RasterDataNode
      Parameters:
      x - x offset into the band
      y - y offset into the band
      w - width of the pixel array to be written
      h - height of the pixel array to be written.
      pixels - double array to be written
    • ensureRasterData

      public void ensureRasterData()
      Ensures that raster data exists
    • loadRasterData

      public void loadRasterData(ProgressMonitor pm) throws IOException
      Loads the complete underlying raster data.

      After this method has been called successfully, hasRasterData() should always return true and getRasterData() should always return a valid ProductData instance with at least getRasterWidth()*getRasterHeight() elements (samples).

      In opposite to the readRasterDataFully method, loadRasterData will only read data if this has not already been done.

      Overrides:
      loadRasterData in class RasterDataNode
      Parameters:
      pm - a monitor to inform the user about progress
      Throws:
      IOException - if an I/O error occurs
      See Also:
    • unloadRasterData

      public void unloadRasterData()
      Un-loads the raster data for this band.

      After this method has been called successfully, the hasRasterData() method returns false and getRasterData() returns null.

      Overrides:
      unloadRasterData in class RasterDataNode
      See Also: