org.geotools.image.io.text
Class TextRecordImageReader

java.lang.Object
  extended by javax.imageio.ImageReader
      extended by org.geotools.image.io.GeographicImageReader
          extended by org.geotools.image.io.StreamImageReader
              extended by org.geotools.image.io.text.TextImageReader
                  extended by org.geotools.image.io.text.TextRecordImageReader

public class TextRecordImageReader
extends TextImageReader

Image decoder for text files storing pixel values as records. Such text files use one line (record) by pixel. Each line contains at least 3 columns (in arbitrary order):

For example, some Sea Level Anomaly (SLA) files contains rows of longitude (degrees), latitude (degrees), SLA (cm), East/West current (cm/s) and North/South current (cm/s), as below:
 45.1250 -29.8750    -7.28     10.3483     -0.3164
 45.1250 -29.6250    -4.97     11.8847      3.6192
 45.1250 -29.3750    -2.91      3.7900      3.0858
 45.1250 -29.1250    -3.48     -5.1833     -5.0759
 45.1250 -28.8750    -4.36     -1.8129    -16.3689
 45.1250 -28.6250    -3.91      7.5577    -24.6801
 
(...etc...)
From this decoder point of view, the two first columns (longitude and latitude) are pixel's logical coordinate (x,y), while the three last columns are three image's bands. The whole file contains only one image (unless GeographicImageReader.getNumImages(boolean) has been overridden). All (x,y) coordinates belong to pixel's center. This decoder will automatically translate (x,y) coordinates from logical space to pixel space.

By default, TextRecordImageReader assumes that x and y coordinates appear in column #0 and 1 respectively. It also assumes that numeric values are encoded using current defaults Charset and Locale, and that there is no pad value. The easiest way to change the default setting is to create a TextRecordImageReader.Spi subclass. There is no need to subclass TextRecordImageReader, unless you want more control on the decoding process.

Since:
2.1
Version:
$Id: TextRecordImageReader.java 30965 2008-07-09 10:04:21Z cedricbr $
Author:
Martin Desruisseaux (IRD)

Nested Class Summary
static class TextRecordImageReader.Spi
          Service provider interface (SPI) for TextRecordImageReaders.
 
Field Summary
 
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
TextRecordImageReader(javax.imageio.spi.ImageReaderSpi provider)
          Constructs a new image reader.
 
Method Summary
protected  int getColumnX(int imageIndex)
          Returns the column number for x values.
protected  int getColumnY(int imageIndex)
          Returns the column number for x values.
 int getHeight(int imageIndex)
          Returns the height in pixels of the given image within the input source.
 javax.imageio.metadata.IIOMetadata getImageMetadata(int imageIndex)
          Returns metadata associated with the given image.
 int getNumBands(int imageIndex)
          Returns the number of bands available for the specified image.
 int getWidth(int imageIndex)
          Returns the width in pixels of the given image within the input source.
 java.awt.image.BufferedImage read(int imageIndex, javax.imageio.ImageReadParam param)
          Reads the image indexed by imageIndex and returns it as a complete buffered image.
 void reset()
          Restores the TextRecordImageReader to its initial state.
protected  void round(double[] values)
          Rounds the specified values.
 void setInput(java.lang.Object input, boolean seekForwardOnly, boolean ignoreMetadata)
          Set the input source.
 
Methods inherited from class org.geotools.image.io.text.TextImageReader
close, getCharset, getLineFormat, getPadValue, getPositionString, getReader, isComment
 
Methods inherited from class org.geotools.image.io.StreamImageReader
dispose, finalize, getInputStream, getStreamLength
 
Methods inherited from class org.geotools.image.io.GeographicImageReader
checkBandIndex, checkImageIndex, collapseNoDataValues, flipVertically, getDefaultReadParam, getDestination, getDimension, getGeographicMetadata, getImageTypes, getNumImages, getRawDataType, getRawImageType, getRawImageType, getStreamMetadata, 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, isRandomAccessEasy, 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
 

Constructor Detail

TextRecordImageReader

public TextRecordImageReader(javax.imageio.spi.ImageReaderSpi provider)
Constructs a new image reader.

Parameters:
provider - the provider that is invoking this constructor, or null if none.
Method Detail

getColumnX

protected int getColumnX(int imageIndex)
                  throws java.io.IOException
Returns the column number for x values. The default implementation returns TextRecordImageReader.Spi.xColumn. Subclasses should override this method if this information should be obtained in an other way.

Parameters:
imageIndex - The index of the image to be queried.
Throws:
java.io.IOException - If an error occurs reading the from the input source.

getColumnY

protected int getColumnY(int imageIndex)
                  throws java.io.IOException
Returns the column number for x values. The default implementation returns TextRecordImageReader.Spi.yColumn. Subclasses should override this method if this information should be obtained in an other way.

Parameters:
imageIndex - The index of the image to be queried.
Throws:
java.io.IOException - If an error occurs reading the from the input source.

setInput

public void setInput(java.lang.Object input,
                     boolean seekForwardOnly,
                     boolean ignoreMetadata)
Set the input source. It should be one of the following object, in preference order: File, URL, BufferedReader. Reader, InputStream or ImageInputStream.

Overrides:
setInput in class StreamImageReader
Parameters:
input - The input object to use for future decoding.
seekForwardOnly - If true, images and metadata may only be read in ascending order from this input source.
ignoreMetadata - If true, metadata may be ignored during reads.
See Also:
ImageReader.getInput(), StreamImageReader.getInputStream()

getNumBands

public int getNumBands(int imageIndex)
                throws java.io.IOException
Returns the number of bands available for the specified image.

Overrides:
getNumBands in class GeographicImageReader
Parameters:
imageIndex - The image index.
Throws:
java.io.IOException - if an error occurs reading the information from the input source.

getWidth

public int getWidth(int imageIndex)
             throws java.io.IOException
Returns the width in pixels of the given image within the input source.

Specified by:
getWidth in class javax.imageio.ImageReader
Parameters:
imageIndex - the index of the image to be queried.
Returns:
Image width.
Throws:
java.io.IOException - If an error occurs reading the width information from the input source.

getHeight

public int getHeight(int imageIndex)
              throws java.io.IOException
Returns the height in pixels of the given image within the input source.

Specified by:
getHeight in class javax.imageio.ImageReader
Parameters:
imageIndex - the index of the image to be queried.
Returns:
Image height.
Throws:
java.io.IOException - If an error occurs reading the height information from the input source.

getImageMetadata

public javax.imageio.metadata.IIOMetadata getImageMetadata(int imageIndex)
                                                    throws java.io.IOException
Returns metadata associated with the given image. Calling this method may force loading of full image.

Overrides:
getImageMetadata in class GeographicImageReader
Parameters:
imageIndex - The image index.
Returns:
The metadata, or null if none.
Throws:
java.io.IOException - If an error occurs reading the data information from the input source.

round

protected void round(double[] values)
Rounds the specified values. This method is invoked automatically by the read method while reading an image. It provides a place where to fix rounding errors in latitude and longitude coordinates. For example if longitudes have a step 1/6° but are written with only 3 decimal digits, then we get x values like 10.000, 10.167, 10.333, etc., which can leads to an error of 0.001° in longitude. This error may cause TextRecordImageReader to fails validation tests and throws an IIOException: "Points dont seem to be distributed on a regular grid". A work around is to multiply the x and y coordinates by 6, round to the nearest integer and divide them by 6.

The default implementation do nothing.

Parameters:
values - The values to round in place.

read

public java.awt.image.BufferedImage read(int imageIndex,
                                         javax.imageio.ImageReadParam param)
                                  throws java.io.IOException
Reads the image indexed by imageIndex and returns it as a complete buffered image.

Specified by:
read in class javax.imageio.ImageReader
Parameters:
imageIndex - the index of the image to be retrieved.
param - Parameters used to control the reading process, or null.
Returns:
the desired portion of the image.
Throws:
java.io.IOException - if an error occurs during reading.

reset

public void reset()
Restores the TextRecordImageReader to its initial state.

Overrides:
reset in class StreamImageReader


Copyright © 1996-2010 Geotools. All Rights Reserved.