Class RasterReader

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

public final class RasterReader extends Object
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
Author:
Johann Sorel (Geomatys), Martin Desruisseaux (Geomatys)
  • Field Details

    • 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.
  • 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.
    • 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.