Class RasterStore
java.lang.Object
org.apache.sis.storage.DataStore
org.apache.sis.internal.storage.URIDataStore
org.apache.sis.internal.storage.PRJDataStore
org.apache.sis.internal.storage.esri.RasterStore
- All Implemented Interfaces:
AutoCloseable
,ResourceOnFileSystem
,StoreResource
,DataSet
,GridCoverageResource
,Resource
,Localized
- Direct Known Subclasses:
AsciiGridStore
,RawRasterStore
Base class for the implementation of ASCII Grid or raw binary store.
This base class manages the reading of following auxiliary files:
*.stx
for statistics about bands.*.clr
for the image color map.*.prj
for the CRS definition.
- Since:
- 1.2
- Version:
- 1.2
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.sis.internal.storage.PRJDataStore
PRJDataStore.AuxiliaryContent, PRJDataStore.Provider
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final String
The filename extension of"*.stx"
and"*.clr"
files.private ColorModel
The color model, created from the"*.clr"
file content when first needed.(package private) org.opengis.metadata.Metadata
The metadata object, ornull
if not yet created.(package private) static final String
Keyword for the number of columns in the image.(package private) double
The value to replace by NaN values, orDouble.NaN
if none.(package private) static final String
Keyword for the number of rows in the image.private static final short[]
Default names of bands when the color model is RGB or RGBA.private List
<SampleDimension> The sample dimensions, created from the"*.stx"
file content when first needed.(package private) static final String
The filename extension of"*.stx"
and"*.clr"
files.private static final int
Band to make visible if an image contains many bands but a color map is defined for only one band.Fields inherited from class org.apache.sis.internal.storage.PRJDataStore
crs, encoding, PRJ
Fields inherited from class org.apache.sis.internal.storage.URIDataStore
location
-
Constructor Summary
ConstructorsConstructorDescriptionRasterStore
(DataStoreProvider provider, StorageConnector connector) Creates a new raster store from the given file, URL or stream. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
canNotReadAuxiliaryFile
(String suffix, Exception exception) Sends a warning about a failure to read an optional auxiliary file.void
close()
Closes this data store and releases any underlying resources.(package private) final GridCoverage2D
createCoverage
(GridGeometry domain, RangeArgument range, WritableRaster data, Statistics stats) Creates the grid coverage resulting from aGridCoverageResource.read(GridGeometry, int...)
operation.(package private) final void
createMetadata
(String formatName, String formatKey) Builds metadata and assigns the result to themetadata
field.Path[]
Returns the URIDataStore.location as aPath
component together with auxiliary files.Returns the sample dimensions computed byloadBandDescriptions(…)
.(package private) final void
loadBandDescriptions
(String name, SampleModel sm, Statistics... stats) Loads"*.stx"
and"*.clr"
files if present then buildssampleDimensions
andcolorModel
from those information.private ColorModel
readColorMap
(int dataType, int mapSize, int numBands) Reads the"*.clr"
auxiliary file.private Statistics[]
readStatistics
(String name, SampleModel sm) Reads the"*.stx"
auxiliary file.Methods inherited from class org.apache.sis.internal.storage.PRJDataStore
deleteAuxiliaryFile, getOpenParameters, listComponentFiles, readAuxiliaryFile, readPRJ, writeAuxiliaryFile, writePRJ
Methods inherited from class org.apache.sis.internal.storage.URIDataStore
addTitleOrIdentifier, getIdentifier, getOriginator, getSpecifiedPath, location, parameters
Methods inherited from class org.apache.sis.storage.DataStore
addListener, findResource, getDisplayName, getLocale, getMetadata, getNativeMetadata, getProvider, removeListener, setLocale, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.sis.storage.GridCoverageResource
getGridGeometry, getLoadingStrategy, getResolutions, read, setLoadingStrategy, subset
Methods inherited from interface org.apache.sis.storage.Resource
addListener, getIdentifier, getMetadata, removeListener
-
Field Details
-
VISIBLE_BAND
private static final int VISIBLE_BANDBand to make visible if an image contains many bands but a color map is defined for only one band.- See Also:
-
NROWS
Keyword for the number of rows in the image.- See Also:
-
NCOLS
Keyword for the number of columns in the image.- See Also:
-
STX
The filename extension of"*.stx"
and"*.clr"
files.- See Also:
-
CLR
The filename extension of"*.stx"
and"*.clr"
files.- See Also:
-
colorModel
The color model, created from the"*.clr"
file content when first needed. The color model and sample dimensions are created together because they depend on the same properties. -
sampleDimensions
The sample dimensions, created from the"*.stx"
file content when first needed. The sample dimensions and color model are created together because they depend on the same properties. This list is unmodifiable.- See Also:
-
nodataValue
double nodataValueThe value to replace by NaN values, orDouble.NaN
if none. -
metadata
org.opengis.metadata.Metadata metadataThe metadata object, ornull
if not yet created. -
RGB_BAND_NAMES
private static final short[] RGB_BAND_NAMESDefault names of bands when the color model is RGB or RGBA.
-
-
Constructor Details
-
RasterStore
RasterStore(DataStoreProvider provider, StorageConnector connector) throws DataStoreException Creates a new raster store from the given file, URL or stream.- Parameters:
provider
- the factory that created thisDataStore
instance, ornull
if unspecified.connector
- information about the storage (file, URL, stream, etc).- Throws:
DataStoreException
- if an error occurred while creating the data store for the given storage.
-
-
Method Details
-
getComponentFiles
Returns the URIDataStore.location as aPath
component together with auxiliary files.- Specified by:
getComponentFiles
in interfaceResourceOnFileSystem
- Overrides:
getComponentFiles
in classPRJDataStore
- Returns:
- the main file and auxiliary files as paths, or an empty array if unknown.
- Throws:
DataStoreException
- if the URI cannot be converted to aPath
.
-
createMetadata
Builds metadata and assigns the result to themetadata
field.- Parameters:
formatName
- name of the raster format.formatKey
- key of format description in theSpatialMetadata
database.- Throws:
DataStoreException
- if an error occurred during the parsing process.
-
readColorMap
private ColorModel readColorMap(int dataType, int mapSize, int numBands) throws DataStoreException, IOException Reads the"*.clr"
auxiliary file. Syntax is as below, with one line per color:value red green blue
The specification said that lines that do not start with a number shall be ignored as comment. Any characters after the fourth number shall also be ignored and can be used as comment.Limitations
Current implementation requires the data type to beDataBuffer.TYPE_BYTE
orDataBuffer.TYPE_SHORT
. A future version could create scaled color model for floating point values as well.- Parameters:
mapSize
- minimal size of index color model map. The actual size may be larger.numBands
- number of bands in the sample model. Only one of them will be visible.- Returns:
- the color model, or
null
if the file does not contain enough entries. - Throws:
NoSuchFileException
- if the auxiliary file has not been found (when opened from path).FileNotFoundException
- if the auxiliary file has not been found (when opened from URL).IOException
- if another error occurred while opening the stream.NumberFormatException
- if a number cannot be parsed.DataStoreException
-
readStatistics
private Statistics[] readStatistics(String name, SampleModel sm) throws DataStoreException, IOException Reads the"*.stx"
auxiliary file. Syntax is as below, with one line per band. Value between {…} are optional and can be skipped with a # sign in place of the number.band minimum maximum {mean} {std_deviation} {linear_stretch_min} {linear_stretch_max}
The specification said that lines that do not start with a number shall be ignored as comment.- Returns:
- statistics for each band. Some elements may be null if not specified in the file.
- Throws:
NoSuchFileException
- if the auxiliary file has not been found (when opened from path).FileNotFoundException
- if the auxiliary file has not been found (when opened from URL).IOException
- if another error occurred while opening the stream.NumberFormatException
- if a number cannot be parsed.DataStoreException
-
loadBandDescriptions
final void loadBandDescriptions(String name, SampleModel sm, Statistics... stats) throws DataStoreException Loads"*.stx"
and"*.clr"
files if present then buildssampleDimensions
andcolorModel
from those information. If no color map is found, a grayscale color model is created.- Parameters:
name
- name to use for the sample dimension, ornull
if untitled.sm
- the sample model to use for creating a default color model if no"*.clr"
file is found.stats
- if the caller collected statistics by itself, those statistics for each band. Otherwise empty.- Throws:
DataStoreException
- if an error occurred while loading an auxiliary file.
-
canNotReadAuxiliaryFile
Sends a warning about a failure to read an optional auxiliary file. This is used for errors that affect only the rendering, not the georeferencing.- Parameters:
suffix
- suffix of the auxiliary file.exception
- error that occurred while reading the auxiliary file.
-
createCoverage
final GridCoverage2D createCoverage(GridGeometry domain, RangeArgument range, WritableRaster data, Statistics stats) Creates the grid coverage resulting from aGridCoverageResource.read(GridGeometry, int...)
operation.- Parameters:
domain
- the effective domain after intersection and subsampling.range
- indices of selected bands.data
- the loaded data.stats
- statistics to save as a property, ornull
if none.- Returns:
- the grid coverage.
-
getSampleDimensions
Returns the sample dimensions computed byloadBandDescriptions(…)
. Shall be overridden by subclasses in a synchronized method. The subclass must ensure thatloadBandDescriptions(…)
has been invoked once.- Specified by:
getSampleDimensions
in interfaceGridCoverageResource
- Returns:
- the sample dimensions, or
null
if not yet computed. - Throws:
DataStoreException
- if an error occurred while reading definitions from the underlying data store.- See Also:
-
close
Closes this data store and releases any underlying resources. Shall be overridden by subclasses in a synchronized method.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in classDataStore
- Throws:
DataStoreException
- if an error occurred while closing this data store.- See Also:
-