Class RasterReader
java.lang.Object
org.apache.sis.internal.sql.postgis.RasterFormat
org.apache.sis.internal.sql.postgis.RasterReader
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-nullInfoStatements
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 Summary
FieldsModifier and TypeFieldDescriptionprivate Band[]
Information about each band (including pixel values), ornull
if none.private ByteBuffer
A temporary buffer for the bytes in the process of being decoded.private SampleModel
The sample model using during the last read operation, for opportunistic reuse of existing instance.org.opengis.referencing.crs.CoordinateReferenceSystem
The default Coordinate Reference System (CRS) if the raster does not specify a CRS.private AffineTransform2D
Conversion from pixel coordinates to CRS coordinates.private int
The spatial reference identifier, or 0 if undefined.Fields inherited from class org.apache.sis.internal.sql.postgis.RasterFormat
ANCHOR, spatialRefSys
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionchannel
(InputStream input) Wraps the given input stream into a channel that can be used byread(…)
methods in this class.Returns the conversion from pixel coordinates to CRS coordinates found in the last raster read.int
getSRID()
Returns the spatial reference identifier for the last raster read.private static RasterFormatException
malformed
(ChannelDataInput input) Returns the exception to throw for malformed or unsupported WKB data.private boolean
Returnstrue
if the sample dimensions need a transfer function for specifying the "no data" value or for handling the sign of data.readAsCoverage
(ChannelDataInput input) Parses a raster from the given input stream and returns as a coverage.readAsImage
(ChannelDataInput input) Parses a raster from the given input stream and returns as an image.readAsRaster
(ChannelDataInput input) Parses a raster from the given input stream and returns a single tile.void
reset()
Restores this reader to its initial state.
-
Field Details
-
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 defaultCRSThe default Coordinate Reference System (CRS) if the raster does not specify a CRS. This isnull
if there is no default. -
srid
private int sridThe 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
Information about each band (including pixel values), ornull
if none. -
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
A temporary buffer for the bytes in the process of being decoded. Initially null and created when first needed.
-
-
Constructor Details
-
RasterReader
Creates a new reader. If thespatialRefSys
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, ornull
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
Returns the conversion from pixel coordinates to CRS coordinates found in the last raster read. This property is non-null only if aread(…)
method has been invoked andreset()
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 aread(…)
method has been invoked andreset()
has not been invoked.- Returns:
- spatial reference identifier, or 0 if undefined.
-
needsTransferFunction
private boolean needsTransferFunction()Returnstrue
if the sample dimensions need a transfer function for specifying the "no data" value or for handling the sign of data. -
malformed
Returns the exception to throw for malformed or unsupported WKB data. -
readAsRaster
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
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
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
Wraps the given input stream into a channel that can be used byread(…)
methods in this class. The returned channel should be used and discarded before to create a newChannelDataInput
, because this method recycles the sameByteBuffer
.- 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.
-