it.geosolutions.imageio.plugins.arcgrid
Class AsciiGridsImageReader

Object
  extended by ImageReader
      extended by AsciiGridsImageReader

public final class AsciiGridsImageReader
extends ImageReader

Class used for reading ASCII ArcInfo Grid Format (ArcGrid) and ASCII GRASS Grid Format and to create RenderedImages and Rasters.

Author:
Daniele Romagnoli, GeoSolutions., Simone Giannecchini, GeoSolutions.

Field Summary
 
Fields inherited from class ImageReader
availableLocales, ignoreMetadata, input, locale, minIndex, originatingProvider, progressListeners, seekForwardOnly, updateListeners, warningListeners, warningLocales
 
Constructor Summary
AsciiGridsImageReader(AsciiGridsImageReaderSpi originatingProvider)
          Constructor.
 
Method Summary
 void abort()
          Request to abort any current read operation.
protected  boolean abortRequested()
          Checks if a request to abort the current read operation has been made.
 boolean canReadRaster()
          Returns true since this plug-in supports reading just a Raster of pixel data.
protected  void clearAbortRequest()
          Clear any request to abort.
 void dispose()
          Cleans this AsciiGridsImageReader up.
 ImageInputStream getCurrentImageInputStream()
          A simple method which returns the imageInputStream used to perform reading operations
 int getHeight(int imageIndex)
          Returns the height in pixels of the image
 IIOMetadata getImageMetadata(int imageIndex)
          Returns an IIOMetadata object containing metadata associated with the image.
 Iterator<ImageTypeSpecifier> getImageTypes(int imageIndex)
          this method provides suggestions for possible image types that will be used to decode the image.
 int getMinIndex()
          Returns the smallest valid index for reading, 0 for the AsciiGridsImageReader.
 int getNumImages(boolean allowSearch)
          Returns the number of images available from the current input source.
 int getNumThumbnails(int imageIndex)
          Returns the number of thumbnail preview images associated with the given image.
 AsciiGridRaster getRasterReader()
          A simple method which returns the proper AsciiGridRaster used to perform reading operations
 IIOMetadata getStreamMetadata()
          Since Ascii Grid format sources may only contain data for a single image, we return null.
 int getTileHeight(int imageIndex)
          Returns the height of a tile in the image.
 int getTileWidth(int imageIndex)
          Returns the width of a tile in the image.
 int getWidth(int imageIndex)
          Returns the width in pixels of the image
 boolean hasThumbnails(int imageIndex)
          Always return false since the AsciiGridsImageReader does not support thumbnails
 boolean isHasListeners()
           
 boolean isIgnoringMetadata()
          Returns true if the current input source has been marked as allowing metadata to be ignored by passing true as the ignoreMetadata argument to the setInput(java.lang.Object) method.
 boolean isImageTiled(int imageIndex)
          Returns true if the image has been tiled.
 boolean isRandomAccessEasy(int imageIndex)
          Returns true if the storage format of the image places no inherent impediment on random access to pixels.
 boolean isSeekForwardOnly()
          Returns true since we always call the setInput method with the seekForwardOnly argument set to true.
 void processImageProgress(float percentageDone)
           
 BufferedImage read(int imageIndex)
          Simply call the overloaded read method by passing null as value of the ImageReadParam argument.
 BufferedImage read(int imageIndex, ImageReadParam param)
          Reads the raster and return it as a complete BufferedImage using a supplied ImageReadParam
 boolean readerSupportsThumbnails()
          Returns false since AsciiGrid format does not supports thumbnail preview images.
 Raster readRaster(int imageIndex, ImageReadParam param)
          Returns a new Raster object containing the raw pixel data from the image stream, without any color conversion applied.
 BufferedImage readTile(int imageIndex, int tileX, int tileY)
          Reads the tile indicated by the tileX and tileY arguments, returning it as a BufferedImage.
 Raster readTileRaster(int imageIndex, int tileX, int tileY)
          Returns a new Raster object containing the raw pixel data from the tile, without any color conversion applied.
 void reset()
          Resets this AsciiGridsImageReader.
 void setInput(Object input)
          Sets the input for this AsciiGridsImageReader.
 void setInput(Object input, boolean seekForwardOnly)
          A Simple call to the setInput(Object input) method, ignoring all other parameters.
 void setInput(Object input, boolean seekForwardOnly, boolean ignoreMetadata)
          A Simple call to the setInput(Object input) method, ignoring all other parameters.
 
Methods inherited from class ImageReader
addIIOReadProgressListener, addIIOReadUpdateListener, addIIOReadWarningListener, checkReadParamBandSettings, computeRegions, getAspectRatio, getAvailableLocales, getDefaultReadParam, getDestination, getFormatName, getImageMetadata, getInput, getLocale, getOriginatingProvider, getRawImageType, getSourceRegion, getStreamMetadata, getThumbnailHeight, getThumbnailWidth, getTileGridXOffset, getTileGridYOffset, processImageComplete, processImageStarted, processImageUpdate, processPassComplete, processPassStarted, processReadAborted, processSequenceComplete, processSequenceStarted, processThumbnailComplete, processThumbnailPassComplete, processThumbnailPassStarted, processThumbnailProgress, processThumbnailStarted, processThumbnailUpdate, processWarningOccurred, processWarningOccurred, readAll, readAll, readAsRenderedImage, readThumbnail, removeAllIIOReadProgressListeners, removeAllIIOReadUpdateListeners, removeAllIIOReadWarningListeners, removeIIOReadProgressListener, removeIIOReadUpdateListener, removeIIOReadWarningListener, setLocale
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AsciiGridsImageReader

public AsciiGridsImageReader(AsciiGridsImageReaderSpi originatingProvider)
Constructor. It builts up an AsciiGridsImageReader by providing an AsciiGridsImageReaderSpi

Parameters:
originatingProvider - the originating service provider interface
Method Detail

setInput

public void setInput(Object input)
Sets the input for this AsciiGridsImageReader.

Overrides:
setInput in class ImageReader
Parameters:
input - Source the AsciiGridsImageReader will read from NOTE: Constrain on GZipped InputStream If we want to provide explicitly an InputStream (instead of a File) for a GZipped source, we MUST provide a proper previously created GZIPInputStream instead of a simple InputStream. Thus, you need to use Code A) instead of Code B):
//as an instance: File file = new File("example.asc.gz"); //A GZipped Source ... //Code A) GZIPInputStream stream = new GZIPInputStream(new FileInputStream(file)); //Code B) //InputStream stream = new FileInputStream(file);
Otherwise, when calling ImageIO.getImageReaders(stream), (directly or indirectly by a Jai ImageRead Operation), the proper SPI can't correctly try to read the Header in order to decode the input.

getHeight

public int getHeight(int imageIndex)
              throws IOException
Returns the height in pixels of the image

Specified by:
getHeight in class ImageReader
Parameters:
imageIndex - the index of the required image which need to be always 0 since AsciiGrid format supports only single image.
Returns:
the height in pixels of the image
Throws:
IOException

getWidth

public int getWidth(int imageIndex)
             throws IOException
Returns the width in pixels of the image

Specified by:
getWidth in class ImageReader
Parameters:
imageIndex - the index of the required image which need to be always 0 since AsciiGrid format supports only single image.
Returns:
the width in pixels of the image
Throws:
IOException

getNumImages

public int getNumImages(boolean allowSearch)
                 throws IOException
Returns the number of images available from the current input source. Since AsciiGrid input source only contains data for a single image, this method always return "1". The input parameter is simply ignored.

Specified by:
getNumImages in class ImageReader
Returns:
1
Throws:
IOException

getImageTypes

public Iterator<ImageTypeSpecifier> getImageTypes(int imageIndex)
                                           throws IOException
this method provides suggestions for possible image types that will be used to decode the image. In this case, we are suggesting using a 32 bit grayscale image with no alpha component.

Specified by:
getImageTypes in class ImageReader
Parameters:
imageIndex - the index of the required image which need to be always 0 since AsciiGrid format supports only single image.
Returns:
an Iterator containing an ImageTypeSpecifier suggesting to use a 32 bit grayscale image.
Throws:
IOException

getStreamMetadata

public IIOMetadata getStreamMetadata()
                              throws IOException
Since Ascii Grid format sources may only contain data for a single image, we return null. We suggest to use getImageMetadata(0) in order to retrieve valid metadata

Specified by:
getStreamMetadata in class ImageReader
Returns:
null
Throws:
IOException

getImageMetadata

public IIOMetadata getImageMetadata(int imageIndex)
                             throws IOException
Returns an IIOMetadata object containing metadata associated with the image.

Specified by:
getImageMetadata in class ImageReader
Parameters:
imageIndex - the index of the required image which need to be always 0 since AsciiGrid format supports only single image.
Returns:
an IIOMetadata object.
Throws:
IOException

read

public BufferedImage read(int imageIndex,
                          ImageReadParam param)
                   throws IOException
Reads the raster and return it as a complete BufferedImage using a supplied ImageReadParam

Specified by:
read in class ImageReader
Parameters:
imageIndex - the index of the required image which need to be always 0 since AsciiGrid format supports only single image.
param - an ImageReadParam to specify subsampling factors, and sourceRegion settings. Other properties are actually ignored.
Returns:
the desired portion of the image as a BufferedImage
Throws:
IOException
See Also:
ImageReader.read(int, javax.imageio.ImageReadParam)

getTileHeight

public int getTileHeight(int imageIndex)
                  throws IOException
Returns the height of a tile in the image.

Overrides:
getTileHeight in class ImageReader
Parameters:
imageIndex - the index of the required image which need to be always 0 since AsciiGrid format supports only single image.
Returns:
the height of a tile
Throws:
IOException

getTileWidth

public int getTileWidth(int imageIndex)
                 throws IOException
Returns the width of a tile in the image.

Overrides:
getTileWidth in class ImageReader
Parameters:
imageIndex - the index of the required image which need to be always 0 since AsciiGrid format supports only single image.
Returns:
the width of a tile
Throws:
IOException

isImageTiled

public boolean isImageTiled(int imageIndex)
                     throws IOException
Returns true if the image has been tiled. All AsciiGrid sources are untiled. However, when the size of an image is greater than a threshold value, we introduce a tiling mechanism.

Overrides:
isImageTiled in class ImageReader
Parameters:
imageIndex - the index of the required image which need to be always 0 since AsciiGrid format supports only single image.
Returns:
true if the image has been tiled.
Throws:
IOException

isRandomAccessEasy

public boolean isRandomAccessEasy(int imageIndex)
                           throws IOException
Returns true if the storage format of the image places no inherent impediment on random access to pixels. Since each value contained within an AsciiGrid file may be represented with a different number of decimal digits, we need to find/count a specific number of whitespaces before to get a desired pixel value. For this reason, this method returns false

Overrides:
isRandomAccessEasy in class ImageReader
Parameters:
imageIndex - the index of the required image which need to be always 0 since AsciiGrid format supports only single image.
Returns:
false
Throws:
IOException

isSeekForwardOnly

public boolean isSeekForwardOnly()
Returns true since we always call the setInput method with the seekForwardOnly argument set to true.

Overrides:
isSeekForwardOnly in class ImageReader
Returns:
true

read

public BufferedImage read(int imageIndex)
                   throws IOException
Simply call the overloaded read method by passing null as value of the ImageReadParam argument.

Overrides:
read in class ImageReader
Parameters:
imageIndex - the index of the required image which need to be always 0 since AsciiGrid format supports only single image.
Returns:
the whole image as a BufferedImage.
Throws:
IOException
See Also:
read(int, ImageReadParam)

readerSupportsThumbnails

public boolean readerSupportsThumbnails()
Returns false since AsciiGrid format does not supports thumbnail preview images.

Overrides:
readerSupportsThumbnails in class ImageReader
Returns:
false

readRaster

public Raster readRaster(int imageIndex,
                         ImageReadParam param)
                  throws IOException
Returns a new Raster object containing the raw pixel data from the image stream, without any color conversion applied.

Overrides:
readRaster in class ImageReader
Parameters:
imageIndex - the index of the required image which need to be always 0 since AsciiGrid format supports only single image.
param - an ImageReadParam used to control the reading process, or null.
Returns:
the desired portion of the image as a Raster.
Throws:
IOException

readTile

public BufferedImage readTile(int imageIndex,
                              int tileX,
                              int tileY)
                       throws IOException
Reads the tile indicated by the tileX and tileY arguments, returning it as a BufferedImage.

Overrides:
readTile in class ImageReader
Parameters:
imageIndex - the index of the required image which need to be always 0 since AsciiGrid format supports only single image.
tileX - the column index (starting with 0) of the tile to be retrieved.
tileY - the row index (starting with 0) of the tile to be retrieved.
Returns:
the tile as a BufferedImage.
Throws:
IOException

readTileRaster

public Raster readTileRaster(int imageIndex,
                             int tileX,
                             int tileY)
                      throws IOException
Returns a new Raster object containing the raw pixel data from the tile, without any color conversion applied.

Overrides:
readTileRaster in class ImageReader
Parameters:
imageIndex - the index of the required image which need to be always 0 since AsciiGrid format supports only single image.
tileX - the column index (starting with 0) of the tile to be retrieved.
tileY - the row index (starting with 0) of the tile to be retrieved.
Returns:
the tile as a Raster.
Throws:
IOException

canReadRaster

public boolean canReadRaster()
Returns true since this plug-in supports reading just a Raster of pixel data.

Overrides:
canReadRaster in class ImageReader
Returns:
true

getMinIndex

public int getMinIndex()
Returns the smallest valid index for reading, 0 for the AsciiGridsImageReader.

Overrides:
getMinIndex in class ImageReader
Returns:
0

getNumThumbnails

public int getNumThumbnails(int imageIndex)
                     throws IOException
Returns the number of thumbnail preview images associated with the given image. Since AsciiGridsImageReader does not support thumbnails, this method always returns 0.

Overrides:
getNumThumbnails in class ImageReader
Parameters:
imageIndex - the index of the required image which need to be always 0 since AsciiGrid format supports only single image.
Returns:
0
Throws:
IOException

hasThumbnails

public boolean hasThumbnails(int imageIndex)
                      throws IOException
Always return false since the AsciiGridsImageReader does not support thumbnails

Overrides:
hasThumbnails in class ImageReader
Parameters:
imageIndex - the index of the required image which need to be always 0 since AsciiGrid format supports only single image.
Returns:
false
Throws:
IOException

isIgnoringMetadata

public boolean isIgnoringMetadata()
Returns true if the current input source has been marked as allowing metadata to be ignored by passing true as the ignoreMetadata argument to the setInput(java.lang.Object) method.

Overrides:
isIgnoringMetadata in class ImageReader
Returns:
true if the metadata may be ignored.

getRasterReader

public AsciiGridRaster getRasterReader()
A simple method which returns the proper AsciiGridRaster used to perform reading operations

Returns:
Returns the rasterReader.

getCurrentImageInputStream

public ImageInputStream getCurrentImageInputStream()
A simple method which returns the imageInputStream used to perform reading operations

Returns:
Returns the imageInputStream.

dispose

public void dispose()
Cleans this AsciiGridsImageReader up.

Overrides:
dispose in class ImageReader

reset

public void reset()
Resets this AsciiGridsImageReader.

Overrides:
reset in class ImageReader

processImageProgress

public void processImageProgress(float percentageDone)
Overrides:
processImageProgress in class ImageReader

abort

public void abort()
Request to abort any current read operation.

Overrides:
abort in class ImageReader

abortRequested

protected boolean abortRequested()
Checks if a request to abort the current read operation has been made.

Overrides:
abortRequested in class ImageReader

clearAbortRequest

protected void clearAbortRequest()
Clear any request to abort.

Overrides:
clearAbortRequest in class ImageReader

setInput

public void setInput(Object input,
                     boolean seekForwardOnly,
                     boolean ignoreMetadata)
A Simple call to the setInput(Object input) method, ignoring all other parameters.

Overrides:
setInput in class ImageReader

setInput

public void setInput(Object input,
                     boolean seekForwardOnly)
A Simple call to the setInput(Object input) method, ignoring all other parameters.

Overrides:
setInput in class ImageReader

isHasListeners

public boolean isHasListeners()


Copyright © 2006-2010 GeoSolutions. All Rights Reserved.