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:
*.stxfor statistics about bands.*.clrfor the image color map.*.prjfor 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 StringThe filename extension of"*.stx"and"*.clr"files.private ColorModelThe color model, created from the"*.clr"file content when first needed.(package private) org.opengis.metadata.MetadataThe metadata object, ornullif not yet created.(package private) static final StringKeyword for the number of columns in the image.(package private) doubleThe value to replace by NaN values, orDouble.NaNif none.(package private) static final StringKeyword 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 StringThe filename extension of"*.stx"and"*.clr"files.private static final intBand 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, PRJFields 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 voidcanNotReadAuxiliaryFile(String suffix, Exception exception) Sends a warning about a failure to read an optional auxiliary file.voidclose()Closes this data store and releases any underlying resources.(package private) final GridCoverage2DcreateCoverage(GridGeometry domain, RangeArgument range, WritableRaster data, Statistics stats) Creates the grid coverage resulting from aGridCoverageResource.read(GridGeometry, int...)operation.(package private) final voidcreateMetadata(String formatName, String formatKey) Builds metadata and assigns the result to themetadatafield.Path[]Returns the URIDataStore.location as aPathcomponent together with auxiliary files.Returns the sample dimensions computed byloadBandDescriptions(…).(package private) final voidloadBandDescriptions(String name, SampleModel sm, Statistics... stats) Loads"*.stx"and"*.clr"files if present then buildssampleDimensionsandcolorModelfrom those information.private ColorModelreadColorMap(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, writePRJMethods inherited from class org.apache.sis.internal.storage.URIDataStore
addTitleOrIdentifier, getIdentifier, getOriginator, getSpecifiedPath, location, parametersMethods inherited from class org.apache.sis.storage.DataStore
addListener, findResource, getDisplayName, getLocale, getMetadata, getNativeMetadata, getProvider, removeListener, setLocale, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.sis.storage.GridCoverageResource
getGridGeometry, getLoadingStrategy, getResolutions, read, setLoadingStrategy, subsetMethods 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.NaNif none. -
metadata
org.opengis.metadata.Metadata metadataThe metadata object, ornullif 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 thisDataStoreinstance, ornullif 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 aPathcomponent together with auxiliary files.- Specified by:
getComponentFilesin interfaceResourceOnFileSystem- Overrides:
getComponentFilesin 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 themetadatafield.- Parameters:
formatName- name of the raster format.formatKey- key of format description in theSpatialMetadatadatabase.- 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_BYTEorDataBuffer.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
nullif 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 buildssampleDimensionsandcolorModelfrom those information. If no color map is found, a grayscale color model is created.- Parameters:
name- name to use for the sample dimension, ornullif 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, ornullif 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:
getSampleDimensionsin interfaceGridCoverageResource- Returns:
- the sample dimensions, or
nullif 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:
closein interfaceAutoCloseable- Specified by:
closein classDataStore- Throws:
DataStoreException- if an error occurred while closing this data store.- See Also:
-