org.geotoolkit.image.io.mosaic
Class TileManagerFactory

Object
  extended by Factory
      extended by TileManagerFactory

public class TileManagerFactory
extends Factory

Creates TileManager instances from a collection or a directory of tiles.

Since:
2.5
Version:
3.18
Author:
Martin Desruisseaux (Geomatys)
Module:
coverage/geotk-coverageio (download)    View source code for this class

Nested Class Summary
 
Nested classes/interfaces inherited from class Factory
Factory.Availability, Factory.Organizer
 
Field Summary
static TileManagerFactory DEFAULT
          The default instance.
 
Fields inherited from class Factory
EMPTY_HINTS, hints
 
Constructor Summary
protected TileManagerFactory(Hints hints)
          Creates a new factory from the specified hints.
 
Method Summary
 TileManager[] create(Collection<Tile> tiles)
          Creates tile managers from the specified collection of tiles.
 TileManager[] create(File file)
          Creates a tile manager from the given file or directory.
 TileManager[] create(File directory, FileFilter filter, ImageReaderSpi spi)
          Creates tile managers from the files found in the given directory.
 TileManager[] create(Tile... tiles)
          Creates tile managers from the specified array of tiles.
 TileManager[] createFromObject(Object tiles)
          Creates tile managers from the specified object, which may be null.
protected  TileManager createGeneric(Tile[] tiles)
          Creates a single tile manager from the given array of tiles.
 List<Tile> listTiles(ImageReaderSpi provider, File... inputs)
          Returns a list of tiles constructed from the given array of files.
 
Methods inherited from class Factory
availability, dispose, equals, getImplementationHints, hasCompatibleHints, hashCode, setOrdering, toString
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT

public static final TileManagerFactory DEFAULT
The default instance.

Constructor Detail

TileManagerFactory

protected TileManagerFactory(Hints hints)
Creates a new factory from the specified hints.

Parameters:
hints - Optional hints, or null if none.
Method Detail

createFromObject

public TileManager[] createFromObject(Object tiles)
                               throws IOException,
                                      IllegalArgumentException
Creates tile managers from the specified object, which may be null. If non-null, the object shall be an instance of TileManager[], TileManager, Tile[], Collection<Tile> or File.

Parameters:
tiles - The tiles, or null.
Returns:
The tile managers, or null if tiles was null.
Throws:
IllegalArgumentException - if tiles is not an instance of a valid class, or if it is an array or a collection containing null elements.
IOException - If an I/O operation was required and failed.
See Also:
MosaicImageReader.Spi.getInputTypes()

create

public TileManager[] create(File file)
                     throws IOException
Creates a tile manager from the given file or directory.

Parameters:
file - The serialized file or the directory to scan.
Returns:
A tile manager created from the tiles in the given directory.
Throws:
IOException - If the given file is not recognized, or an I/O operation failed.
Since:
3.15

create

public TileManager[] create(File directory,
                            FileFilter filter,
                            ImageReaderSpi spi)
                     throws IOException
Creates tile managers from the files found in the given directory. This method scans also the sub-directories recursively if the given file filter accepts directories.

First, this method fetches the list of all filtered files in the directory and sub-directories. Then this method invokes the listTiles(ImageReaderSpi, File[]) method for converting the list of files into a list of Tile instances. Note that in current implementation, this implies that each image file in the given directory shall have a World File of the same name, typically with the ".tfw" extension. Finally this method builds the tiles manager using the create(Collection) method.

If the file filter is null, a default file filter will be created from the given SPI. If the given SPI is null, a SPI will be inferred automatically for each image files found in the directory.

Parameters:
directory - The directory to scan.
filter - An optional file filter, or null for a default filter.
spi - An optional image provider, or null for auto-detect.
Returns:
A tile manager created from the tiles in the given directory.
Throws:
IOException - If the given file is not a directory, or an I/O operation failed.
Since:
3.15

create

public TileManager[] create(Tile... tiles)
                     throws IOException
Creates tile managers from the specified array of tiles. This method usually returns a single tile manager, but more could be returned if this factory has been unable to put every tiles in a single mosaic (for example if the ratio between affine transform given to tile constructor would lead to fractional subsampling).

Parameters:
tiles - The tiles to give to a tile manager.
Returns:
A tile manager created from the given tiles.
Throws:
IOException - If an I/O operation was required and failed.

create

public TileManager[] create(Collection<Tile> tiles)
                     throws IOException
Creates tile managers from the specified collection of tiles. This method usually returns a single tile manager, but more could be returned if this factory has been unable to put every tiles in a single mosaic (for example if the ratio between affine transform given to tile constructor would lead to fractional subsampling).

Parameters:
tiles - The tiles to give to a tile manager.
Returns:
A tile manager created from the given tiles.
Throws:
IOException - If an I/O operation was required and failed.

createGeneric

protected TileManager createGeneric(Tile[] tiles)
                             throws IOException
Creates a single tile manager from the given array of tiles. This method is automatically invoked by create methods. The tile array has already been cloned and can be stored directly by the tile manager constructors.

Subclasses can override this method if they want to create other kinds of tile managers.

Parameters:
tiles - A copy of user-supplied tiles.
Returns:
The tile manager for the given tiles.
Throws:
IOException - If an I/O operation was required and failed.

listTiles

public List<Tile> listTiles(ImageReaderSpi provider,
                            File... inputs)
                     throws IOException
Returns a list of tiles constructed from the given array of files. Every file in the given array must exist, be a valid image and have a valid World File, i.e. a file of the same name in the same directory then the image file, but with an extension like ".tfw" (for TIFF images) or ".jgw" (for JPEG images).

This method loads the World Files and fetches the image sizes immediately. The world file applies to the first image in the file. If the file contains more than one image, then each additional image is assumed to represent the same data than the first image at a different resolution.

Customization
If the files contain many images but those images are not overviews of the first image at different resolution, then subclasses can use only a specific image by overriding this method as below, where imageIndex is the index of the image to use (typically 0):

public List<Tile> listTiles(final ImageReaderSpi provider, final File... inputs) throws IOException {
    final List<Tile> tiles = new ArrayList<Tile>(inputs.length);
    for (final File input : inputs) {
        tiles.add(new Tile(provider, input, imageIndex));
    }
    return tiles;
}
This method is invoked by create(File, FileFilter, ImageReaderSpi), so it can be overridden for controlling the tiles to be built when TileManagerFactory scans a directory.

Parameters:
provider - The image reader provider to use. If null, the provider will be inferred from each input. If it can't be inferred, then an exception is thrown.
inputs - The image files.
Returns:
The tiles constructed from the image files.
Throws:
IOException - If no World File were found for a given image file, or if an error occurred while reading a file.
Since:
3.18
See Also:
Tile.Tile(ImageReaderSpi, File, int)


Copyright © 2009-2012 Geotoolkit.org. All Rights Reserved.