Class RasterReader

java.lang.Object
org.apache.sis.internal.sql.postgis.RasterFormat
org.apache.sis.internal.sql.postgis.RasterReader

public final class RasterReader extends RasterFormat
A reader of rasters encoded in Well Known Binary (WKB) format. This format is specific to PostGIS 2 (this is not yet an OGC standard at the time of writing this class), but it can nevertheless be used elsewhere.

Multi-threading

This class is not safe for multi-threading. Furthermore, if a non-null InfoStatements has been specified to the constructor, then this object is valid only as long as the caller holds a connection to the database.
Since:
1.2
Version:
1.2
  • Field Details

    • gridToCRS

      private AffineTransform2D gridToCRS
      Conversion from pixel coordinates to CRS coordinates. This is defined by 6 affine transform coefficients similar to the World File format.
    • defaultCRS

      public org.opengis.referencing.crs.CoordinateReferenceSystem defaultCRS
      The default Coordinate Reference System (CRS) if the raster does not specify a CRS. This is null if there is no default.
    • srid

      private int srid
      The spatial reference identifier, or 0 if undefined. Note that this is a primary key in the "spatial_ref_sys" table, not necessarily an EPSG code.
    • bands

      private Band[] bands
      Information about each band (including pixel values), or null if none.
    • cachedModel

      private transient SampleModel cachedModel
      The sample model using during the last read operation, for opportunistic reuse of existing instance. This is effective when reading may rasters of the same type and size.
    • buffer

      private ByteBuffer buffer
      A temporary buffer for the bytes in the process of being decoded. Initially null and created when first needed.
  • Constructor Details

    • RasterReader

      public RasterReader(InfoStatements spatialRefSys)
      Creates a new reader. If the spatialRefSys argument is non-null, then this object is valid only as long as the caller holds a connection to the database.
      Parameters:
      spatialRefSys - the object to use for building CRS from the "spatial_ref_sys" table, or null for using the SRID as an EPSG code.
  • Method Details

    • reset

      public void reset()
      Restores this reader to its initial state. This method can be invoked for reading more than one raster with the same reader.
    • getGridToCRS

      public AffineTransform2D getGridToCRS()
      Returns the conversion from pixel coordinates to CRS coordinates found in the last raster read. This property is non-null only if a read(…) method has been invoked and reset() has not been invoked.
      Returns:
      conversion from pixel coordinates to CRS coordinates, or null if undefined.
    • getSRID

      public int getSRID()
      Returns the spatial reference identifier for the last raster read. This property is non-zero only if a read(…) method has been invoked and reset() has not been invoked.
      Returns:
      spatial reference identifier, or 0 if undefined.
    • needsTransferFunction

      private boolean needsTransferFunction()
      Returns true if the sample dimensions need a transfer function for specifying the "no data" value or for handling the sign of data.
    • malformed

      private static RasterFormatException malformed(ChannelDataInput input)
      Returns the exception to throw for malformed or unsupported WKB data.
    • readAsRaster

      public WritableRaster readAsRaster(ChannelDataInput input) throws IOException
      Parses a raster from the given input stream and returns a single tile.
      Parameters:
      input - source of bytes to read.
      Returns:
      the raster, or null if the raster is empty.
      Throws:
      IOException - in an error occurred while reading from the given input.
      RasterFormatException - if the raster format is not supported by current implementation.
      ArithmeticException - if the raster is too large.
    • readAsImage

      public BufferedImage readAsImage(ChannelDataInput input) throws IOException
      Parses a raster from the given input stream and returns as an image.
      Parameters:
      input - source of bytes to read.
      Returns:
      the raster as an image, or null if the raster is empty.
      Throws:
      IOException - in an error occurred while reading from the given input.
      RasterFormatException - if the raster format is not supported by current implementation.
      ArithmeticException - if the raster is too large.
    • readAsCoverage

      public GridCoverage readAsCoverage(ChannelDataInput input) throws Exception
      Parses a raster from the given input stream and returns as a coverage.
      Parameters:
      input - source of bytes to read.
      Returns:
      the raster as a coverage, or null if the raster is empty.
      Throws:
      Exception - in an error occurred while reading from the given input or creating the coverage. Exception type may be I/O, SQL, factory, data store, arithmetic, raster format, etc., too numerous for enumerating them all.
    • channel

      public ChannelDataInput channel(InputStream input) throws IOException
      Wraps the given input stream into a channel that can be used by read(…) methods in this class. The returned channel should be used and discarded before to create a new ChannelDataInput, because this method recycles the same ByteBuffer.
      Parameters:
      input - the input stream to wrap.
      Returns:
      a channel together with a buffer.
      Throws:
      IOException - if an error occurred while reading data from the input stream.