|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectImageReader
SpatialImageReader
StreamImageReader
TextImageReader
TextRecordImageReader
public class TextRecordImageReader
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:
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, unless45.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...)
SpatialImageReader.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.
Example
The text of the left side is an extract of a list of (longitude, latitude,
elevation of the ocean floor) records. The image on the right side is the image
produced by TextRecordImageReader when reading such file.
# Longitude Latitude Altitude 59.9000 -30.0000 -3022 59.9333 -30.0000 -3194 59.9667 -30.0000 -3888 60.0000 -30.0000 -3888 45.0000 -29.9667 -2502 45.0333 -29.9667 -2502 45.0667 -29.9667 -2576 45.1000 -29.9667 -2576 45.1333 -29.9667 -2624 45.1667 -29.9667 -2690 45.2000 -29.9667 -2690 45.2333 -29.9667 -2692 45.2667 -29.9667 -2606 45.3000 -29.9667 -2606 45.3333 -29.9667 -2528etc... |
![]() |
| coverage/geotk-coverageio (download) | View source code for this class |
| Nested Class Summary | |
|---|---|
static class |
TextRecordImageReader.Spi
Service provider interface (SPI) for TextRecordImageReaders. |
| Field Summary |
|---|
| Fields inherited from class StreamImageReader |
|---|
closeOnReset |
| Fields inherited from class ImageReader |
|---|
availableLocales, ignoreMetadata, input, locale, minIndex, originatingProvider, progressListeners, seekForwardOnly, updateListeners, warningListeners, warningLocales |
| Fields inherited from interface WarningProducer |
|---|
LOGGER |
| Constructor Summary | |
|---|---|
TextRecordImageReader(TextRecordImageReader.Spi provider)
Constructs a new image reader. |
|
| Method Summary | |
|---|---|
protected void |
close()
Closes the reader created by TextImageReader.getReader(). |
protected SpatialMetadata |
createMetadata(int imageIndex)
Returns metadata associated with the given image. |
protected int |
getColumnX(int imageIndex)
Returns the column number for x values. |
protected int |
getColumnY(int imageIndex)
Returns the column number for y values. |
int |
getHeight(int imageIndex)
Returns the height in pixels of the given image within the input source. |
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. |
BufferedImage |
read(int imageIndex,
ImageReadParam param)
Reads the image indexed by imageIndex and returns it as a buffered image. |
protected void |
round(double[] values)
Invoked during read operation for rounding a record of values. |
| Methods inherited from class TextImageReader |
|---|
getCharset, getLineFormat, getPadValue, getPositionString, getReader, isComment |
| Methods inherited from class StreamImageReader |
|---|
finalize, getChannel, getInputStream, getStreamLength, setInput |
| Methods inherited from class Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface Localized |
|---|
getLocale |
| Constructor Detail |
|---|
public TextRecordImageReader(TextRecordImageReader.Spi provider)
provider - The ImageReaderSpi that is constructing this object, or null.| Method Detail |
|---|
protected int getColumnX(int imageIndex)
throws IOException
TextRecordImageReader.Spi.xColumn, or 0 if no service prodiver were specified
to the constructor. Subclasses should override this method if this information should
be obtained in an other way.
imageIndex - The index of the image to be queried.
IOException - If an error occurs while reading the from the input source.
protected int getColumnY(int imageIndex)
throws IOException
TextRecordImageReader.Spi.yColumn, or 1 if no service prodiver were specified
to the constructor. Subclasses should override this method if this information should
be obtained in an other way.
imageIndex - The index of the image to be queried.
IOException - If an error occurs while reading the from the input source.
public int getNumBands(int imageIndex)
throws IOException
getNumBands in class SpatialImageReaderimageIndex - The image index.
IOException - if an error occurs while reading the information from the input source.
public int getWidth(int imageIndex)
throws IOException
getWidth in class ImageReaderimageIndex - the index of the image to be queried.
IOException - If an error occurs while reading the width information
from the input source.
public int getHeight(int imageIndex)
throws IOException
getHeight in class ImageReaderimageIndex - the index of the image to be queried.
IOException - If an error occurs while reading the height information
from the input source.
protected SpatialMetadata createMetadata(int imageIndex)
throws IOException
createMetadata in class SpatialImageReaderimageIndex - The image index.
null if none.
IOException - If an error occurs reading the data information from the input source.protected void round(double[] values)
read operation for rounding a record of values. The default
implementation does nothing. The main purpose of this method is to give to subclasses an
opportunity to fix rounding errors in latitude and longitude coordinates.
Example
Assume that the longitudes in a file are likely to have an interval of 1/6° but are written
with only 3 decimal digits. In such case, the x values look 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 as in the code below (which is doing the same process to latitude):
int xColumn = getColumnX(); int yColumn = getColumnY(); values[xColumn] = XMath.roundIfAlmostInteger(values[xColumn] * 6, 3) / 6; values[yColumn] = XMath.roundIfAlmostInteger(values[yColumn] * 6, 3) / 6;
values - The values to round in place.
public BufferedImage read(int imageIndex,
ImageReadParam param)
throws IOException
imageIndex and returns it as a buffered image.
read in class ImageReaderimageIndex - The index of the image to be retrieved.param - Parameters used to control the reading process, or null.
IOException - If an error occurs during reading.
protected void close()
throws IOException
TextImageReader.getReader(). This method does nothing if
the reader is the input instance given by the user rather
than a reader created by this class from a File or URL input.
close in class TextImageReaderIOException - If an error occurred while closing the reader.StreamImageReader.closeOnReset
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||