|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.imageio.ImageReader
org.geotools.image.io.GeographicImageReader
org.geotools.image.io.StreamImageReader
org.geotools.image.io.FileImageReader
org.geotools.image.io.netcdf.NetcdfImageReader
public class NetcdfImageReader
Base implementation for NetCDF image reader. Pixels are assumed organized according the COARDS convention (a precursor of CF Metadata conventions), i.e. in (t,z,y,x) order, where x varies faster. The image is created from the two last dimensions (x,y). Additional dimensions (if any) are handled as below in the default implementation:
NetcdfReadParam.setBandDimensionTypes(ucar.nc2.constants.AxisType...)
method.NetcdfReadParam.setSliceIndice(ucar.nc2.constants.AxisType, int)
method.
Example:
Assuming that:
IIOParam.setSourceBands(int[])
.
If no band is selected, then the default selection is the first band (0) only. Note that this
is different than the usual Image I/O default, which is all bands.
Connection to DODS servers
This image reader accepts File
and URL
inputs. In the later case, if and only
if the URL uses the DODS protocol (as in "dods://opendap.aviso.oceanobs.com/
"), then
this image reader tries to connect to the DODS remote server. Otherwise the URL content is
copied in a temporary file.
Nested Class Summary | |
---|---|
static class |
NetcdfImageReader.Spi
The service provider for NetcdfImageReader . |
Field Summary | |
---|---|
protected ucar.nc2.Variable |
variable
The data from the NetCDF file. |
Fields inherited from class org.geotools.image.io.StreamImageReader |
---|
closeOnReset |
Fields inherited from class javax.imageio.ImageReader |
---|
availableLocales, ignoreMetadata, input, locale, minIndex, originatingProvider, progressListeners, seekForwardOnly, updateListeners, warningListeners, warningLocales |
Constructor Summary | |
---|---|
NetcdfImageReader(NetcdfImageReader.Spi spi)
Constructs a new NetCDF reader. |
Method Summary | |
---|---|
protected void |
close()
Closes the NetCDF file. |
protected javax.imageio.metadata.IIOMetadata |
createMetadata(ucar.nc2.dataset.NetcdfDataset file)
Creates metadata for the specified NetCDF file. |
protected javax.imageio.metadata.IIOMetadata |
createMetadata(ucar.nc2.dataset.VariableDS variable)
Creates metadata for the specified NetCDF variable. |
protected ucar.nc2.Variable |
findVariable(java.lang.String name)
Returns the variable of the given name. |
javax.imageio.ImageReadParam |
getDefaultReadParam()
Returns parameters initialized with default values appropriate for this format. |
int |
getDimension(int imageIndex)
Returns the number of dimension of the image at the given index. |
int |
getHeight(int imageIndex)
Returns the image height. |
javax.imageio.metadata.IIOMetadata |
getImageMetadata(int imageIndex)
Returns the metadata associated with the image at the specified index. |
int |
getNumBands(int imageIndex)
Returns the number of bands available for the specified image. |
int |
getNumImages(boolean allowSearch)
Returns the number of images available from the current input source. |
protected int |
getRawDataType(int imageIndex)
Returns the data type which most closely represents the "raw" internal data of the image. |
Statistics |
getStatistics(int imageIndex)
Returns statistics about the sample values in the specified image. |
javax.imageio.metadata.IIOMetadata |
getStreamMetadata()
Returns the metadata associated with the input source as a whole. |
java.lang.String[] |
getVariables()
Returns the names of the variables to be read. |
int |
getWidth(int imageIndex)
Returns the image width. |
boolean |
isCancel()
Invoked by the NetCDF library during read operation in order to check if the task has been canceled. |
protected boolean |
prepareVariable(int imageIndex)
Ensures that data are loaded in the NetCDF variable. |
java.awt.image.BufferedImage |
read(int imageIndex,
javax.imageio.ImageReadParam param)
Creates an image from the specified parameters. |
void |
setError(java.lang.String message)
Invoked by the NetCDF library when an error occured during the read operation. |
void |
setVariables(java.lang.String[] variableNames)
Sets the name of the variables to be read in a NetCDF file. |
Methods inherited from class org.geotools.image.io.FileImageReader |
---|
getInputFile, getURLEncoding, isRandomAccessEasy, isTemporaryFile |
Methods inherited from class org.geotools.image.io.StreamImageReader |
---|
dispose, finalize, getInputStream, getStreamLength, reset, setInput |
Methods inherited from class org.geotools.image.io.GeographicImageReader |
---|
checkBandIndex, checkImageIndex, collapseNoDataValues, flipVertically, getDestination, getGeographicMetadata, getImageTypes, getRawImageType, getRawImageType, read, warningOccurred |
Methods inherited from class javax.imageio.ImageReader |
---|
abort, abortRequested, addIIOReadProgressListener, addIIOReadUpdateListener, addIIOReadWarningListener, canReadRaster, checkReadParamBandSettings, clearAbortRequest, computeRegions, getAspectRatio, getAvailableLocales, getDestination, getFormatName, getImageMetadata, getInput, getLocale, getMinIndex, getNumThumbnails, getOriginatingProvider, getSourceRegion, getStreamMetadata, getThumbnailHeight, getThumbnailWidth, getTileGridXOffset, getTileGridYOffset, getTileHeight, getTileWidth, hasThumbnails, isIgnoringMetadata, isImageTiled, isSeekForwardOnly, processImageComplete, processImageProgress, processImageStarted, processImageUpdate, processPassComplete, processPassStarted, processReadAborted, processSequenceComplete, processSequenceStarted, processThumbnailComplete, processThumbnailPassComplete, processThumbnailPassStarted, processThumbnailProgress, processThumbnailStarted, processThumbnailUpdate, processWarningOccurred, processWarningOccurred, readAll, readAll, readAsRenderedImage, readerSupportsThumbnails, readRaster, readThumbnail, readTile, readTileRaster, removeAllIIOReadProgressListeners, removeAllIIOReadUpdateListeners, removeAllIIOReadWarningListeners, removeIIOReadProgressListener, removeIIOReadUpdateListener, removeIIOReadWarningListener, setInput, setInput, setLocale |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected ucar.nc2.Variable variable
prepareVariable(int)
when first needed. This is typically (but not necessarly) an instance of VariableDS
.
Constructor Detail |
---|
public NetcdfImageReader(NetcdfImageReader.Spi spi)
spi
- The service provider.Method Detail |
---|
public java.lang.String[] getVariables() throws java.io.IOException
read(imageIndex)
will read the variable names
variables[imageIndex]
where variables
is the value returned by this
method.
The sequence of variable to be read can be changed by a call to setVariables(java.lang.String[])
.
java.io.IOException
- if the NetCDF file can not be read.public void setVariables(java.lang.String[] variableNames)
If variableNames
is set to null
(which is the default), then the
variables will be inferred from the content of the NetCDF file.
variableNames
- The set of variables to be assigned to image index.public int getNumImages(boolean allowSearch) throws java.lang.IllegalStateException, java.io.IOException
getNumImages
in class GeographicImageReader
allowSearch
- If true, the number of images will be returned
even if a search is required.
allowSearch
is false and a search would be required.
java.lang.IllegalStateException
- if the input source has not been set.
java.io.IOException
- if an error occurs reading the information from the input source.public int getNumBands(int imageIndex) throws java.io.IOException
getNumBands
in class GeographicImageReader
imageIndex
- The image index.
java.io.IOException
- if an error occurs reading the information from the input source.public int getDimension(int imageIndex) throws java.io.IOException
getDimension
in class GeographicImageReader
imageIndex
- The image index.
java.io.IOException
- if an error occurs reading the information from the input source.public Statistics getStatistics(int imageIndex) throws java.io.IOException
imageIndex
- The index of the image to analyze.
java.io.IOException
- if an I/O error occured while reading the sample values.public int getWidth(int imageIndex) throws java.io.IOException
getWidth
in class javax.imageio.ImageReader
java.io.IOException
- If an error occured while reading the NetCDF file.public int getHeight(int imageIndex) throws java.io.IOException
getHeight
in class javax.imageio.ImageReader
java.io.IOException
- If an error occured while reading the NetCDF file.public javax.imageio.metadata.IIOMetadata getStreamMetadata() throws java.io.IOException
getStreamMetadata
in class GeographicImageReader
java.io.IOException
- If an error occured while reading the NetCDF file.public javax.imageio.metadata.IIOMetadata getImageMetadata(int imageIndex) throws java.io.IOException
getImageMetadata
in class GeographicImageReader
imageIndex
- The image index.
null
if none.
java.io.IOException
- If an error occured while reading the NetCDF file.protected javax.imageio.metadata.IIOMetadata createMetadata(ucar.nc2.dataset.NetcdfDataset file) throws java.io.IOException
getStreamMetadata()
when first needed. The default implementation returns an
instance of NetcdfMetadata
. Subclasses can override this method in order to create
a more specific set of metadata.
file
- The NetCDF dataset.
java.io.IOException
- If an error occured while reading the NetCDF file.protected javax.imageio.metadata.IIOMetadata createMetadata(ucar.nc2.dataset.VariableDS variable) throws java.io.IOException
getImageMetadata(int)
when first needed. The default implementation returns an
instance of NetcdfMetadata
. Subclasses can override this method in order to create
a more specific set of metadata.
variable
- The NetCDF variable.
java.io.IOException
- If an error occured while reading the NetCDF file.protected int getRawDataType(int imageIndex) throws java.io.IOException
getRawDataType
in class GeographicImageReader
imageIndex
- The index of the image to be queried.
DataBuffer.TYPE_UNDEFINED
if unknown.
java.io.IOException
- If an error occured while reading the NetCDF file.GeographicImageReader.getRawImageType(int, ImageReadParam, SampleConverter[])
protected boolean prepareVariable(int imageIndex) throws java.io.IOException
This method is invoked automatically before any operation that require the NetCDF variable, including (but not limited to):
getWidth(int)
getHeight(int)
getStatistics(int)
getImageMetadata(int)
getRawDataType(int)
read(int,ImageReadParam)
imageIndex
- The image index.
true
if the variable changed as a result of this call,
or false
if the current value is already appropriate.
java.lang.IndexOutOfBoundsException
- if the specified index is outside the expected range.
java.lang.IllegalStateException
- If ImageReader.input
is not set.
java.io.IOException
- If an error occured while reading the NetCDF file.protected ucar.nc2.Variable findVariable(java.lang.String name) throws java.io.IOException
NetcdfFile.findVariable(String)
except that the search
is case-insensitive and an exception is thrown if no variable has
been found for the given name.
name
- The name of the variable to search.
javax.imageio.IIOException
- if no variable has been found for the given name.
java.io.IOException
- If an error occured while reading the NetCDF file.public javax.imageio.ImageReadParam getDefaultReadParam()
getDefaultReadParam
in class GeographicImageReader
public java.awt.image.BufferedImage read(int imageIndex, javax.imageio.ImageReadParam param) throws java.io.IOException
read
in class javax.imageio.ImageReader
java.io.IOException
- If an error occured while reading the NetCDF file.public boolean isCancel()
isCancel
in interface ucar.nc2.util.CancelTask
true
if abort has been requested.public void setError(java.lang.String message)
setError
in interface ucar.nc2.util.CancelTask
message
- An error message to report.protected void close() throws java.io.IOException
close
in class FileImageReader
java.io.IOException
- If an error occured while accessing the NetCDF file.StreamImageReader.closeOnReset
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |