|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectBuilder<TileManager>
MosaicBuilder
@ThreadSafe public class MosaicBuilder
Creates TileManager from a set of images organized according a given
tile layout. This class can work with pre-existing
tile files (in which case it just build a TileManager), or can write
the tiles to the disk if the files do not already exist.
Example creating tiles to disk
For example in order to create a mosaic for a set of tiles of size 256×256 pixels,
with overviews having pixels 2, 3 and 4 times the width and height of original pixels and
for writing the tiles in the "output" directory, use the following:
Object originalMosaic = ...; // May be a File, URL, list of Tiles, etc.
MosaicBuilder builder = new MosaicBuilder();
builder.setTileDirectory(new File("output"));
builder.setTileSize(new Dimension(256, 256));
builder.setSubsamplings(1, 2, 3, 4);
TileManager newMosaic = builder.writeFromInput(originalMosaic, null);
MosaicBuilderEditor
| coverage/geotk-coverageio (download) | View source code for this class |
| Field Summary | |
|---|---|
protected TileManagerFactory |
factory
The factory to use for creating TileManager instances. |
| Constructor Summary | |
|---|---|
MosaicBuilder()
Creates a new instance which will use the default tile manager factory. |
|
MosaicBuilder(TileManagerFactory factory)
Generates tiles using the specified tile manager factory. |
|
| Method Summary | |
|---|---|
TileManager |
build()
Creates a tile manager from the informations supplied in above setters. |
TileManager |
createTileManager()
Creates a tile manager from the informations supplied in above setters. |
TileManager |
createTileManager(Object input)
Creates a tile manager from an untiled image. |
protected String |
generateFilename(int level,
int column,
int row)
Generates a filename for the current tile based on the position of this tile in the raster. |
AffineTransform |
getGridToCRS()
Returns the transform from mosaic pixel coordinates to mosaic geodetic coordinates, or null if none. |
Level |
getLogLevel()
Returns the logging level for information about tiles being read and written. |
Dimension[] |
getSubsamplings()
Returns the subsampling for overview computations. |
File |
getTileDirectory()
Returns the tile directory, or null for current directory. |
TileLayout |
getTileLayout()
Returns the tile layout. |
ImageReaderSpi |
getTileReaderSpi()
Returns the image reader provider to use for reading tiles. |
Dimension |
getTileSize()
Returns the tile size. |
Rectangle |
getUntiledImageBounds()
Returns the grid envelope (in pixels) of the mosaic as a whole, or null
if not set. |
IIOListeners |
listeners()
Returns a modifiable collection of image I/O listeners. |
protected void |
onTileWrite(Tile tile,
ImageWriteParam parameters)
Invoked automatically when a tile is about to be written. |
void |
setGridToCRS(AffineTransform tr)
Sets the transform from mosaic pixel coordinates to mosaic geodetic coordinates. |
void |
setLogLevel(Level level)
Sets the logging level for information about tiles being read and written. |
void |
setSubsamplings(Dimension... subsamplings)
Sets the subsamplings for overview computations. |
void |
setSubsamplings(int... subsamplings)
Sets uniform subsamplings for overview computations. |
void |
setTileDirectory(File directory)
Sets the directory where tiles will be read or written. |
void |
setTileLayout(TileLayout layout)
Sets the tile layout to the specified value. |
void |
setTileReaderSpi(ImageReaderSpi provider)
Sets the image reader provider for each tiles to be read. |
void |
setTileReaderSpi(String format)
Sets the image reader provider by name. |
void |
setTileSize(Dimension size)
Sets the tile size. |
void |
setUntiledImageBounds(Rectangle bounds)
Sets the grid envelope (in pixels) of the mosaic as a whole. |
static int |
suggestedTileSize(int imageSize,
int tileSize,
int minSize,
int maxSize)
Returns a suggested tile size (width or height) for the given image size. |
TileManager |
writeFromInput(Object input,
int inputIndex,
MosaicImageWriteParam param)
Creates the tile manager and writes the tiles on disk. |
TileManager |
writeFromInput(Object input,
MosaicImageWriteParam param)
Creates the tile manager and writes the tiles on disk. |
| Methods inherited from class Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final TileManagerFactory factory
TileManager instances.
| Constructor Detail |
|---|
public MosaicBuilder()
public MosaicBuilder(TileManagerFactory factory)
factory - The factory to use, or null for the
default one.| Method Detail |
|---|
public Level getLogLevel()
PerformanceLevel constants, determined
according the duration of the operation.
getLogLevel in interface LogProducerpublic void setLogLevel(Level level)
null
value restores the default level documented in the getLogLevel() method.
setLogLevel in interface LogProducerlevel - The new logging level.public TileLayout getTileLayout()
MosaicBuilder
will lay out the new tiles relative to each other. For example if the pixels in an image
overview cover a geographic area 2 time larger (in width and height) than the
pixels in an original image, then we have a choice:
CONSTANT_GEOGRAPHIC_AREA).CONSTANT_TILE_SIZE).
The default value is CONSTANT_TILE_SIZE.
public void setTileLayout(TileLayout layout)
CONSTANT_TILE_SIZE and
CONSTANT_GEOGRAPHIC_AREA.
layout - An identification of new tile layout.public File getTileDirectory()
null for current directory. This is the directory
where writeFromInput methods will
write the new tiles, if writing tiles is allowed. This is also the directory where the
TileManager created by the above methods will read the tiles back.
The directory may be either relative or absolute. The default value is null.
public void setTileDirectory(File directory)
null (the default) for current directory.
directory - The new tiles directory.public ImageReaderSpi getTileReaderSpi()
null, which means that the provider should be the same
than the one detected by createTileManager(Object) from its input argument.
public void setTileReaderSpi(ImageReaderSpi provider)
null value means that the provider should be automatically detected by
createTileManager(Object).
It is recommended to avoid WorldFileImageReader provider, in order to avoid
unnecessary attempts to read the ".tfw" and ".prj" files. Callers
can use the following code:
setTileReaderSpi(WorldFileImageReader.Spi.unwrap(provider));
provider - The new image reader provider for tiles.
public void setTileReaderSpi(String format)
throws IllegalArgumentException
IIORegistry and delegates to
setTileReaderSpi(ImageReaderSpi).
format - The image format name for tiles.
IllegalArgumentException - if no provider was found for the given name.public AffineTransform getGridToCRS()
null if none. This transform is optional. If specified, then the builder
will forward this value to TileManager.setGridToCRS(AffineTransform).
null if none.public void setGridToCRS(AffineTransform tr)
TileManager.setGridToCRS(AffineTransform).
Tips
GridToEnvelopeMapper.RectifiedGrid,
then the transform can be computed from the rectified
grid using MetadataHelper.
tr - The pixel to geodetic transform, or null if none.public Rectangle getUntiledImageBounds()
null
if not set. In the later case, the bounds will be inferred from the input image
when createTileManager(Object) is invoked.
null.public void setUntiledImageBounds(Rectangle bounds)
null value discards any value previously set.
bounds - The new grid envelope of the mosaic, or null.public Dimension getTileSize()
null.
suggestedTileSize(int)public void setTileSize(Dimension size)
null value discards any value previously set.
size - The new tile size.
public static int suggestedTileSize(int imageSize,
int tileSize,
int minSize,
int maxSize)
throws IllegalArgumentException
[minSize...maxSize]
range where imageSize/x has the largest amount of
divisors. If more than one value have the same amount
of divisors, then the one which is the closest to tileSize is returned.
imageSize - The image size.tileSize - The preferred tile size. Must be inside the [minSize...maxSize] range.minSize - The minimum size, inclusive. Must be greater than 0.maxSize - The maximum size, inclusive. Must be equals or greater that minSize.
[minSize...maxSize]
range except if imageSize was smaller than minSize.
IllegalArgumentException - if any argument doesn't meet the above-cited conditions.public Dimension[] getSubsamplings()
If no subsampling can be computed, then this method returns null.
public void setSubsamplings(Dimension... subsamplings)
MosaicBuilder will be equal to the subsamplings array length.
Subsamplings most be explicitly provided for TileLayout.CONSTANT_GEOGRAPHIC_AREA,
but is optional for TileLayout.CONSTANT_TILE_SIZE. In the later case subsamplings
may be null (the default), in which case they will be automatically computed from
the untiled image bounds and tile size in order to have only entire tiles (i.e. tiles in last columns and last rows
don't need to be cropped).
subsamplings - The new subsamplings for each overview levels.public void setSubsamplings(int... subsamplings)
setSubsamplings(Dimension[]) with the same value affected to both
width and height.
subsamplings - The new subsamplings for each overview levels.
public TileManager build()
throws BackingStoreException
createTileManager(),
wrapping any potential IOException into a BackingStoreException.
build in class Builder<TileManager>BackingStoreException - if createTileManager() threw IOException.
public TileManager createTileManager()
throws IOException
The other setter methods are optional.
IOException - if an I/O operation was required and failed. The default implementation
does not perform any I/O, but subclasses are allowed to do so.
public TileManager createTileManager(Object input)
throws IOException
File
if the mosaic should be created from a single input image, or may be a collection of
Tiles or a TileManager if the new mosaic should be created from an
existing one.
This method does not write any tile to disk.
input - The image input, typically as a File or an other TileManager.
null if the process has been aborted.
IOException - if an error occurred while reading the untiled image.
public TileManager writeFromInput(Object input,
MosaicImageWriteParam param)
throws IOException
writeFromInput(input,
0, policy) except that this method ensures that the input contains only one
image. If more than one image is found, then an exception is throw. This is often desireable
when the input is a collection of Tiles, since having more than one "image" (where
"image" in this context means different instances of TileManager) means that we
failed to create a single mosaic from a set of source tiles.
input - The image input, typically as a File or an other TileManager.param - The parameter to be given to MosaicImageWriter, or null
for the default parameters.
null if the process has been aborted while writing tiles.
IOException - if an error occurred while reading the untiled image or while writing
the tiles to disk.
public TileManager writeFromInput(Object input,
int inputIndex,
MosaicImageWriteParam param)
throws IOException
File
if the mosaic should be created from a single input image, or may be a collection of
Tiles or a TileManager if the new mosaic should be created from an
existing one.
input - The image input, typically as a File or an other TileManager.inputIndex - Index of image to read, typically 0.param - The parameter to be given to MosaicImageWriter, or null
for the default parameters.
null if the process has been aborted while writing tiles.
IOException - if an error occurred while reading the untiled image or while writing
the tiles to disk.public IIOListeners listeners()
addIIOReadProgressListener and
addIIOWriteProgressListener can
be invoked on the returned object. The read listeners are used when reading the
input mosaic, while the write listeners are used when writing the output mosaic.
protected String generateFilename(int level,
int column,
int row)
L1_E2.png".
Subclasses may override this method if they want more control on generated tile filenames.
level - The level of overview. First level is 0.column - The index of columns. First column is 0.row - The index of rows. First row is 0.
protected void onTileWrite(Tile tile,
ImageWriteParam parameters)
throws IOException
The source region and
source subsampling parameters can not be
set through this method. Their setting will be overwritten by the caller because their
values depend on the strategy chosen by MosaicImageWriter for reading images,
which itself depends on the amount of available memory.
tile - The tile to be written.parameters - The parameters to be given to the image writer.
IOException - if an I/O operation was required and failed.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||