Class TiledGridCoverage.AOI
- Direct Known Subclasses:
TiledGridCoverage.Snapshot, TiledGridCoverage.TileIterator
- Enclosing class:
TiledGridCoverage
AOI can be a mutable iterator over all the tiles to read (TiledGridCoverage.TileIterator) or an immutable snapshot
of the iterator position as an instant (TiledGridCoverage.Snapshot).- Since:
- 1.7
-
Method Summary
Modifier and TypeMethodDescriptionStores the given raster in the cache for the current AOI position.Creates an initially empty raster for the tile at the current AOI position.Returns the cached tile for current AOI position.getRegionInsideTile(boolean subsampled) Returns the coordinates of the pixels to read relative to the current tile's upper-left corner.booleangetRegionInsideTile(long[] lower, long[] upper, long[] subsampling, boolean subsampled) Returns the clipped coordinates of the cells to read relative to the tile's upper-left corner.final long[]Returns the current AOI position in the tile matrix of the original resource.final intReturns the current AOI position as an index in the vector of tiles of the original resource.final intReturns the current AOI position as an index in the array of tiles to be returned byTiledGridCoverage.readTiles(…).Creates the coordinates of the upper-left corner of the tile at the current AOI position.Returns the location (relative to the cropped tile) of the upper-left corner of the uncropped tile.moveRaster(Raster tile) Returns the given raster relocated at the current AOI position.
-
Method Details
-
getTileCoordinatesInResource
public final long[] getTileCoordinatesInResource()Returns the current AOI position in the tile matrix of the original resource. This method assumes that the upper-left corner of tile (0,0) in the resource starts at cell coordinates (0,0) of the resource.- Returns:
- current AOI tile coordinates in original coverage resource.
-
getTileIndexInResource
public final int getTileIndexInResource()Returns the current AOI position as an index in the vector of tiles of the original resource. Tiles are assumed stored in a row-major fashion. with the first tiles starting at index 0.- Returns:
- current AOI tile index in original coverage resource.
-
getTileIndexInResultArray
public final int getTileIndexInResultArray()Returns the current AOI position as an index in the array of tiles to be returned byTiledGridCoverage.readTiles(…). If this AOI is an iterator, the initial position is zero and is incremented by 1 in each call toTiledGridCoverage.TileIterator.next().- Returns:
- current AOI tile index in the result array of tiles.
- See Also:
-
getCachedTile
Returns the cached tile for current AOI position. This method returns the value given in a call to thecache(Raster)during a previous iteration when the iterator was at the same position, if that raster has not yet been garbage collected.- Returns:
- cached tile at current AOI position, or
nullif none. - See Also:
-
cache
Stores the given raster in the cache for the current AOI position. If a raster is already in the cache and has the same size and equal sample model, then the given raster is ignored and the existing raster is returned on the assumption that it has the same content.- Parameters:
tile- the raster to cache.- Returns:
- the cached raster. Should be the given
rasterinstance, unless this method is invoked during two concurrent reads of the same tile. - See Also:
-
createRaster
Creates an initially empty raster for the tile at the current AOI position. The sample model isTiledGridCoverage.modeland the minimum x and y position are set to the pixel coordinates in two dimensions of the AOI.The raster is not filled with
TiledGridCoverage.fillValues. Filling, if needed, should be done by the caller.If some resource's listeners have registered an interest for tile read events, and if these listeners have not yet been notified about the reading of the specified tile, then a
TileReadEventis sent to these listeners. This policy is based on the fact that this method is typically invoked before a tile is read.- Returns:
- a newly created, initially empty raster.
- See Also:
-
moveRaster
Returns the given raster relocated at the current AOI position. This method does not need to be invoked for tiles created bycreateRaster(), but may need to be invoked for tiles created by a method external to this class, such asImageReader.readTileRaster(int, int, int). If the given raster is already at the current AOI position, then this method returns that raster directly.- Parameters:
tile- the raster to move at the current AOI position.- Returns:
- the relocated raster (may be
rasteritself). - See Also:
-
getTileLocation
Creates the coordinates of the upper-left corner of the tile at the current AOI position. This is the (minX,minY) values of the tile created bycreateRaster().- Returns:
- coordinates of the upper-left pixel of the tile at the current iterator position.
- See Also:
-
getUncroppedTileLocation
Returns the location (relative to the cropped tile) of the upper-left corner of the uncropped tile. This value is present under the following conditions:- Reading an image made of a single potentially huge tile, and
- the huge tile is cropped for avoiding to read that tile in whole.
This value can be added to the coordinates of a point for converting from uncropped tile coordinates to cropped tile coordinates. See
getRegionInsideTile(boolean)for a code snippet.- Returns:
- the location (relative to the cropped tile) of the upper-left corner of the uncropped tile.
-
getRegionInsideTile
Returns the coordinates of the pixels to read relative to the current tile's upper-left corner. The upper-left corner of the uncropped tile is assumed to have the coordinates (0,0). Therefore, the (x, y) location computed by this method is usually (0,0) and the rectangle size is usually the tile size, but those values may be different if the enclosingTiledGridCoveragecontains only one (potentially large) tile. The rectangle may also be smaller when reading tiles on the last row or column of the tile matrix.Subsampling
If thesubsampledargument isfalse, then this method returns coordinates relative to the tile in the originatingTiledGridCoverageResource, i.e. without subsampling. Ifsubsampledistrue, then this method returns coordinates relative to the raster, i.e. with subsampling.Conversion to raster space
Because this rectangle is relative to the uncropped tile, the raster origin needs to be added to the rectangle location for obtaining coordinates in the raster space. Furthermore, in the special case where the region to read is made of one potentially huge tile,TiledGridCoveragemay have cropped the tile. In the latter case, the rectangle location also needs to be shifted by subtracting thegetUncroppedTileLocation()value. Generally, the code can be as below:WritableRaster tile = iterator.createRaster(); Rectangle validArea = iterator.getRegionInsideTile(true); if (validArea != null) { // Conversion from relative to absolute tile's coordinates. validArea.translate(tile.getMinX(), tile.getMinY()); // Conversion to coordinates to read in the underlying resource. Rectangle sourceArea = iterator.imageToResource(validArea, false); // Conversion from uncropped coordinates to cropped coordinates. iterator.getUncroppedTileLocation().ifPresent((p) -> sourceArea.translate(p.x, p.y)); }- Parameters:
subsampled- whether to return coordinates with subsampling applied.- Returns:
- pixel to read inside the tile, or
nullif the region is empty. - Throws:
ArithmeticException- if the tile coordinates overflow 32-bits integer capacity.- See Also:
-
getRegionInsideTile
public boolean getRegionInsideTile(long[] lower, long[] upper, long[] subsampling, boolean subsampled) Returns the clipped coordinates of the cells to read relative to the tile's upper-left corner. The upper-left corner of the uncropped tile is assumed to have the coordinates (0,0,0,…). Therefore, the lower bounds computed by this method are usually (0,0,0,…) and the upper bounds (before subsampling) are usually the tile size, but those values may be different if the enclosingTiledGridCoveragecontains only one tile. The bounds may also be smaller when reading tiles on the last row or column of the tile matrix.The
TiledGridCoveragesubsampling is provided for convenience, but is constant for all tiles regardless the subregion to read. The same values can be obtained byTiledGridCoverage.getSubsampling(int).This method is a generalization of
getRegionInsideTile(boolean)to any number of dimensions. See that method for a discussion about thesubsampledargument and a code snippet. The given arrays can be of any length, but that length must be the same for all arguments. If the given arrays are longer than necessary, the result is truncated to the arrays length. If the given arrays are longer than necessary, the extraneous array elements are unchanged.- Parameters:
lower- a pre-allocated array where to store relative coordinates of the first pixel.upper- a pre-allocated array where to store relative coordinates after the last pixel.subsampling- a pre-allocated array where to store subsampling, ornullif not needed.subsampled- whether to return coordinates with subsampling applied.- Returns:
trueon success, orfalseif the tile is empty.- Throws:
ArrayIndexOutOfBoundsException- if the given arrays are not of the same length.
-