Skip navigation links


Base classes for extensions to ImageReader and ImageWriter for spatial data.

See: Description

Package Description

Base classes for extensions to ImageReader and ImageWriter for spatial data. This package provides the following classes which can be used as a base for plugin implementations:

ImageReader ImageWriter Purpose
SpatialImageReader SpatialImageWriter Base class for readers/writers of spatial (usually geographic) data.
StreamImageReader StreamImageWriter Base class for readers/writers working with InputStream/OutputStream or channels. Other kind of input/output are converted to stream when first needed.
TextImageReader TextImageWriter Base class for readers/writers working with Reader/Writer. This implies the use of a character encoding, which may be local-dependent.
FileImageReader FileImageWriter Base class for readers/writers that require File input or output. Other kind of input/output are copied in a temporary file. This is used for wrapping native libraries which doesn't work with Java streams.
ImageReaderAdapter ImageWriterAdapter Base class for readers/writers which delegate most of their work to an other reader/writer. This is used for appending additional metadata to the ones processed by the standard readers/writers.
ImageReadParam ImageWriteParam Purpose
SpatialImageReadParam SpatialImageWriteParam Specializations of the standard IIOParam class for multi-dimensional dataset and for specifying color palette.
IIOMetadata Purpose
SpatialMetadata Geographic metadata structured in an arborescence similar to ISO 19115-2.

Concrete implementations are provided in the plugin and mosaic sub-packages. The Java Image I/O library is designed for two-dimensional images. The Geotk library extends the Java library with the MultidimensionalImageStore interface, which provide method for accessing data above the two first dimensions. See the MultidimensionalImageStore javadoc for more details. Spatial image formats often contain geophysical values (e.g. temperatures in Celsius degrees, elevation in metres, etc.) better represented as floating point numbers than integers. Those files may be simple ASCII files containing values written as decimal numbers, or RAW files containing values written in the IEEE 754 binary format. Those files may contains missing values represented by a "pad" or "fill" value. The SpatialImageReader class provides SampleConverter for:

The default sample type is DataBuffer.TYPE_FLOAT. This default value is a compromise between compactness and reducing the risk of information lost. However rendering floating-point images is usually very slow. After reading, users can exploit Java Advanced Imaging operations in order to reformat data as needed. The example below reformats the TYPE_FLOAT data into TYPE_BYTE and replaces the grayscale colors by an indexed color model.

import java.awt.RenderingHints;
import java.awt.image.DataBuffer;
import java.awt.image.IndexColorModel;
import java.awt.image.renderable.ParameterBlock;

public class Example {
    public static RenderedImage reformat(RenderedImage image) {
        // Prepare the indexed color model. Arrays
        // R, G and B should contains 256 RGB values.
        final byte[] R = ...
        final byte[] G = ...
        final byte[] B = ...
        final IndexColorModel colors = new IndexColorModel(8, 256, R, G, B);
        final ImageLayout     layout = new ImageLayout().setColorModel(colorModel);
        final RenderingHints   hints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout);

        // Rescale the image.   First, all pixels values are transformed using
        // the equation pi=CO+C1*p. Then, type float is clamp to type byte and
        // the new index color model is set.   Displaying such an image should
        // be much faster.
        final double C0 = ...
        final double C1 = ...
        image = RescaleDescriptor.create(image, new double[] {C1}, new double[] {C0}, null);
        image = FormatDescriptor .create(image, DataBuffer.TYPE_BYTE, null);
        return image;
The XImageIO class provides static methods completing the ones provided in the standard ImageIO class. Those methods consider the input or output type before to select an image reader or writer, because not every plugins can accept the standard types (image input or output stream) defined by the Java Image I/O specification.

The CoverageIO class provides higher-level static methods related to GridCoverage I/O operations. While not mandatory, it is recommended to invoke the following methods at least once before to use the Geotk library. Those methods are not invoked automatically in order to let users control their application configuration.

  1. Invoke some AWT method first; see setDefaultCodecPreferences() below for explanation.
  2. Registry.setDefaultCodecPreferences()
  3. WorldFileImageReader.Spi.registerDefaults(ServiceRegistry)
  4. WorldFileImageWriter.Spi.registerDefaults(ServiceRegistry)

Alternative: Setup.initialize(Properties) performs (among other tasks) all the above tasks except 1.

Those methods can be invoked more than once if the set of standard readers available (PNG, TIFF, etc.) is changed. For example invoking WorldFileImageReader.Spi.registerDefaults(...) again will replace the old World File readers by new one wrapping the new standard readers.

Martin Desruisseaux (IRD, Geomatys), Antoine Hnawia (IRD)
See Also:

Defined in the geotk-coverage module

Skip navigation links

Copyright © 2009–2017 All rights reserved.