Class RasterWriter

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

public final class RasterWriter extends RasterFormat
A writer 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

    • byteOrder

      private ByteOrder byteOrder
      The byte order to use for encoding the WKB.
    • gridToCRS

      private AffineTransform gridToCRS
      Conversion from pixel coordinates to CRS coordinates. This is defined by 6 affine transform coefficients similar to the World File format.
    • 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.
    • noDataValues

      private Number[] noDataValues
      The "no data" value for each band, or null if none. If the array length is greater than the number of bands, the last elements are ignored. If the array length is smaller than the number of bands, all remaining bands are assumed to have no "no data" value.
  • Constructor Details

    • RasterWriter

      public RasterWriter(InfoStatements spatialRefSys)
      Creates a new writer. 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 mapping CRS to the "spatial_ref_sys" table, or null for using the EPSG codes.
  • Method Details

    • reset

      public void reset()
      Restores this writer to its initial state. It resets the byte order, grid to CRS transform and SRID to their default values.
    • setGridToCRS

      public void setGridToCRS(GridGeometry gg) throws Exception
      Sets the conversion from grid coordinates to CRS coordinates together with target CRS. The conversion must be affine. Other grid properties (e.g. envelope and extent) are ignored.
      Parameters:
      gg - the grid to CRS conversion together with target CRS.
      Throws:
      IllegalArgumentException - if the "grid to CRS" transform is not affine.
      Exception - if an error occurred during the search for SRID code. May be SQL error, WKT parsing error, factory error, etc.
    • setNodataValues

      public void setNodataValues(List<? extends SampleDimension> bands)
      Infers the "no data" values from the given sample dimensions. This method uses the background value if available.
      Parameters:
      bands - the sample dimensions from which to infer the "no data" values.
    • write

      public void write(GridCoverage coverage, ChannelDataOutput output) throws Exception
      Encodes the given grid coverage to the specified output. This method sets the "grid to CRS" conversion and the no data values, then delegates to write(RenderedImage, ChannelDataOutput).
      Parameters:
      coverage - the grid coverage to encode.
      output - where to write the bytes.
      Throws:
      RasterFormatException - if the raster to write is not supported.
      IOException - in an error occurred while writing to the given output.
      Exception - if an error occurred during the search for SRID code. May be SQL error, WKT parsing error, factory error, etc.
    • write

      public void write(RenderedImage image, ChannelDataOutput output) throws IOException
      Encodes the given image to the specified output.
      Parameters:
      image - the image to encode.
      output - where to write the bytes.
      Throws:
      RasterFormatException - if the raster to write is not supported.
      IOException - in an error occurred while writing to the given output.
    • write

      public void write(Raster raster, ChannelDataOutput output) throws IOException
      Encodes the given raster to the specified output.
      Parameters:
      raster - the raster to encode.
      output - where to write the bytes.
      Throws:
      RasterFormatException - if the raster to write is not supported.
      IOException - in an error occurred while writing to the given output.
    • ensureUnsignedShort

      private static int ensureUnsignedShort(String name, int value)
      Ensures that the given value is in the range of unsigned short.
      Parameters:
      name - name of the value, for error message.
      value - the value to check.
      Returns:
      value.