|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.geotools.image.io.mosaic.MosaicBuilder
public class MosaicBuilder
A convenience class for building tiles using the same image reader and organized according some common tile layout. Optionally, this builder can also write the tiles to disk from an initially untiled image.
Field Summary | |
---|---|
protected TileManagerFactory |
factory
The factory to use for creating TileManager instances. |
Constructor Summary | |
---|---|
MosaicBuilder()
Generates tiles using the default factory. |
|
MosaicBuilder(TileManagerFactory factory)
Generates tiles using the specified factory. |
Method Summary | |
---|---|
protected GridToEnvelopeMapper |
createGridToEnvelopeMapper(TileManager tiles)
Invoked automatically when a "grid to CRS" transform needs to be computed. |
TileManager |
createTileManager()
Creates a tile manager from the informations supplied in above setters. |
TileManager |
createTileManager(java.lang.Object input)
Creates a tile manager from an untiled image. |
TileManager |
createTileManager(java.lang.Object input,
int inputIndex,
TileWritingPolicy policy)
Creates a tile manager from an untiled image. |
protected java.lang.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. |
java.util.logging.Level |
getLogLevel()
Returns the logging level for tile information during read and write operations. |
org.opengis.geometry.Envelope |
getMosaicEnvelope()
Returns the envelope for the mosaic as a whole, or null if none. |
java.awt.Dimension[] |
getSubsamplings()
Returns the subsampling for overview computations. |
java.io.File |
getTileDirectory()
Returns the tile directory, or null for current directory. |
TileLayout |
getTileLayout()
Returns the tile layout. |
javax.imageio.spi.ImageReaderSpi |
getTileReaderSpi()
Returns the image reader provider to use for reading tiles. |
java.awt.Dimension |
getTileSize()
Returns the tile size. |
java.awt.Rectangle |
getUntiledImageBounds()
Returns the bounds of the untiled image, or null if not set. |
protected void |
onTileWrite(Tile tile,
javax.imageio.ImageWriteParam parameters)
Invoked automatically when a tile is about to be written. |
void |
setLogLevel(java.util.logging.Level level)
Sets the logging level for tile information during read and write operations. |
void |
setMosaicEnvelope(org.opengis.geometry.Envelope envelope)
Sets the envelope for the mosaic as a whole, or null if none. |
void |
setSubsamplings(java.awt.Dimension[] subsamplings)
Sets the subsamplings for overview computations. |
void |
setSubsamplings(int[] subsamplings)
Sets uniform subsamplings for overview computations. |
void |
setTileDirectory(java.io.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(javax.imageio.spi.ImageReaderSpi provider)
Sets the image reader provider for each tiles to be read. |
void |
setTileReaderSpi(java.lang.String format)
Sets the image reader provider by name. |
void |
setTileSize(java.awt.Dimension size)
Sets the tile size. |
void |
setUntiledImageBounds(java.awt.Rectangle bounds)
Sets the bounds of the untiled image to the specified value. |
static int[][] |
suggestedNumTiles(java.awt.Rectangle imageBounds,
java.awt.Dimension tileSize,
int preferredCount,
boolean multiples)
Returns a suggested set of divisors of the number of tiles that can fit in an image. |
static int |
suggestedTileSize(int imageSize,
int tileSize,
int minSize,
int maxSize)
Returns a suggested tile size (width or height) for the given image size. |
Methods inherited from class java.lang.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 java.util.logging.Level getLogLevel()
public void setLogLevel(java.util.logging.Level level)
Level.FINE
. A null
value restore the default.
level
- The new logging level.public TileLayout getTileLayout()
CONSTANT_TILE_SIZE
, which is the most efficient
layout available in org.geotools.image.io.mosaic
implementation.
public void setTileLayout(TileLayout layout)
CONSTANT_TILE_SIZE
and
CONSTANT_GEOGRAPHIC_AREA
.
layout
- An identification of new tile layout.public java.io.File getTileDirectory()
null
for current directory. The directory
may be either relative or absolute. The default value is null
.
public void setTileDirectory(java.io.File directory)
null
(the default) for current directory.
directory
- The new tiles directory.public javax.imageio.spi.ImageReaderSpi getTileReaderSpi()
null
, which means that the provider should be the same
than the one detected by writeFromUntiledImage
.
public void setTileReaderSpi(javax.imageio.spi.ImageReaderSpi provider)
null
value means that the provider should be automatically detected by
writeFromUntiledImage
.
provider
- The new image reader provider for tiles.public void setTileReaderSpi(java.lang.String format) throws java.lang.IllegalArgumentException
IIORegistry
and delegates to
setTileReaderSpi(ImageReaderSpi)
.
format
- The image format name for tiles.
java.lang.IllegalArgumentException
- if no provider was found for the given name.public org.opengis.geometry.Envelope getMosaicEnvelope()
null
if none. This is optional,
but if specified this builder uses it for assigning values to Tile.getGridToCRS()
.
null
if none.public void setMosaicEnvelope(org.opengis.geometry.Envelope envelope)
null
if none. This is optional,
but if specified this builder uses it for assigning values to Tile.getGridToCRS()
.
This is merely a convenient way to invoke TileManager.setGridToCRS(java.awt.geom.AffineTransform)
with a transform
computed from the envelope and the untiled image bounds,
where the later may be known only at reading time. As always, creating "grid to CRS" from an
envelope is ambiguous, since we don't know if axis need to be interchanged, y axis
flipped, etc. Subclasses can gain more control by overriding the
createGridToEnvelopeMapper
method. The default behavior
fits most typical cases however.
envelope
- The new envelope, or null
if none.createGridToEnvelopeMapper(org.geotools.image.io.mosaic.TileManager)
public java.awt.Rectangle getUntiledImageBounds()
null
if not set. In the later case, the
bounds will be inferred from the input image when #writeFromUntiledImage
is invoked.
public void setUntiledImageBounds(java.awt.Rectangle bounds)
null
value discarts any value previously set.
bounds
- The new untiled image bounds.public java.awt.Dimension getTileSize()
null
.
suggestedTileSize(int)
public void setTileSize(java.awt.Dimension size)
null
value discarts any value previously set.
size
- The new tile size.public static int suggestedTileSize(int imageSize, int tileSize, int minSize, int maxSize) throws java.lang.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
.
java.lang.IllegalArgumentException
- if any argument doesn't meet the above-cited conditions.public static int[][] suggestedNumTiles(java.awt.Rectangle imageBounds, java.awt.Dimension tileSize, int preferredCount, boolean multiples)
int[]
:
divisors(round(imageBounds / tileSize))
The two arrays are then decimated using the following procedures:
multiples
is true
, then the arrays are decimated in such a way
that each value divisors[i]
is a multiple of divisors[i-1]
. This
is useful for getting only tiles that can fit entirely in bigger tiles.
If the number of divisors is lower than the preferredCount
, then this method will
try again for smaller tiles until the preferred count or some other (currently undocumented)
stop condition is reached.
Let r
be the return value. The following contract should hold in all cases:
r
is never null
r.length
is always 2r[0].length
== r[1].length
and this length is greater than 0r[0][0]
== r[1][0]
== 1 (i.e. the first divisor is always 1)
imageBounds
- The image size.tileSize
- The tile size.preferredCount
- The preferred minimal amount of divisors, or 0 if there is no
minimal count.multiples
- If true
, then the returned numbers are restricted to multiples.
public java.awt.Dimension[] getSubsamplings()
If no subsampling can be computed, then this method returns null
.
public void setSubsamplings(java.awt.Dimension[] subsamplings)
MosaicBuilder
will be equals 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 createTileManager() throws java.io.IOException
The other setter methods are optional.
java.io.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(java.lang.Object input) throws java.io.IOException
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.
java.io.IOException
- if an error occured while reading the untiled image.public TileManager createTileManager(java.lang.Object input, int inputIndex, TileWritingPolicy policy) throws java.io.IOException
Optionnaly if the tile writing policy is anything else than
NO_WRITE
, then pixel values are read from the untiled
images, organized in tiles as specified by the TileManager
to be returned and saved
to disk. This work is done using a default MosaicImageWriter
.
input
- The image input, typically as a File
or an other TileManager
.inputIndex
- Index of image to read, typically 0.policy
- Sets whatever tiles are created and saved to disk.
null
if the process has been aborted while writing tiles.
java.io.IOException
- if an error occured while reading the untiled image or (only if
writeTiles
is true
) while writting the tiles to disk.protected java.lang.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 GridToEnvelopeMapper createGridToEnvelopeMapper(TileManager tiles)
GridToEnvelopeMapper
instance in its default
configuration, except for the pixel anchor
which is set to CELL_CORNER
(OGC specification maps pixel
center, while Java I/O maps pixel upper-left corner).
Subclasses may override this method in order to configure the mapper in an other way.
tiles
- The tiles for which a "grid to CRS" transform needs to be computed.
setMosaicEnvelope(org.opengis.geometry.Envelope)
protected void onTileWrite(Tile tile, javax.imageio.ImageWriteParam parameters) throws java.io.IOException
tile
- The tile to be written.parameters
- The parameters to be given to the image writer.
java.io.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 |