Package org.apache.sis.internal.storage
Class TiledGridCoverage
java.lang.Object
org.apache.sis.coverage.BandedCoverage
org.apache.sis.coverage.grid.GridCoverage
org.apache.sis.internal.storage.TiledGridCoverage
- Direct Known Subclasses:
DataSubset
Base class of grid coverage read from a resource where data are stored in tiles.
This grid coverage may represent only a subset of the coverage resource.
Tiles are read from the storage only when first needed.
Cell Coordinates
When there is no subsampling, this coverage uses the same cell coordinates than the originating resource. When there is a subsampling, cell coordinates in this coverage are divided by the subsampling factors. Conversions are done bytoFullResolution(long, int).
Tile coordinate matrix
In eachTiledGridCoverage, indices of tiles starts at (0, 0, …).
This class does not use the same tile indices than the coverage resource
in order to avoid integer overflow.- Since:
- 1.1
- Version:
- 1.2
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected final classThe Area Of Interest specified by user in a call torender(GridExtent).protected static classSnapshot of aTiledGridCoverage.AOIiterator position.Nested classes/interfaces inherited from class org.apache.sis.coverage.grid.GridCoverage
GridCoverage.Evaluator -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intNumber of dimensions in a rendered image.protected final ColorModelThe Java2D color model for images rendered from this coverage.private final booleanWhether the reading of tiles is deferred toRenderedImage.getTile(int, int)time.protected final NumberThe value to use for filling empty spaces in rasters, ornullif zero.private final booleanWhether to force thereadExtenttile intersection to thetileSize.protected final int[]Indices ofTiledGridResourcebands which have been retained for inclusion in thisTiledGridCoverage, in strictly increasing order.private final intIndex of the firstTiledGridCoveragetile in a row-major array of tiles.protected final SampleModelThe sample model for all rasters.private final WeakValueHashMap<TiledGridResource.CacheKey,Raster> Cache of rasters read by thisTiledGridCoverage.private final GridExtentThe area to read in unit of the full coverage (without subsampling).private final int[]Conversion from pixel coordinates in this (potentially subsampled) coverage to pixel coordinates in the resource coverage at full resolution.private final int[]Conversion from pixel coordinates in this (potentially subsampled) coverage to pixel coordinates in the resource coverage at full resolution.private final int[]Size of all tiles in the domain of thisTiledGridCoverage, without clipping and subsampling.private final int[]Values by which to multiply each tile coordinates for obtaining the index in the tile vector.private final long[]The Tile Matrix Coordinates (TMC) of the first tile.protected static final intThe dimensions of x and y axes.protected static final intThe dimensions of x and y axes.Fields inherited from class org.apache.sis.coverage.grid.GridCoverage
gridGeometry -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates a new tiled grid coverage. -
Method Summary
Modifier and TypeMethodDescriptionprivate TiledGridResource.CacheKeycreateCacheKey(int indexInTileVector) Creates the key to use for caching the tile at given index.protected abstract org.opengis.util.GenericNameReturns a unique name that identifies this coverage.protected LocaleReturns the locale for error messages, ornullfor the default.protected final intReturns the number of pixels in a single bank element.(package private) static intgetPixelsPerElement(SampleModel model) Implementation ofgetPixelsPerElement().protected final intgetSubsampling(int dimension) Returns the subsampling in the given dimension.protected final intgetTileSize(int dimension) Returns the size of all tiles in the domain of thisTiledGridCoverage, without clipping and subsampling.protected abstract Raster[]readTiles(TiledGridCoverage.AOI iterator) Returns all tiles in the given area of interest.render(GridExtent sliceExtent) Returns a two-dimensional slice of grid data as a rendered image.private longtoFullResolution(long coordinate, int dimension) Converts a cell coordinate from thisTiledGridCoveragecoordinate space to full resolution.private longtoSubsampledPixel(long coordinate, int dimension) Converts a cell coordinate fromTiledGridResourcespace toTiledGridCoveragecoordinate.private longtoTileMatrixCoordinate(long coordinate, int dimension) Converts a cell coordinate from thisTiledGridCoveragecoordinate space to the Tile Matrix Coordinate (TMC) of the tile which contains that cell.Methods inherited from class org.apache.sis.coverage.grid.GridCoverage
createConvertedValues, evaluator, forConvertedValues, getCoordinateReferenceSystem, getEnvelope, getGridGeometry, getSampleDimensions, toString, toTree
-
Field Details
-
BIDIMENSIONAL
protected static final int BIDIMENSIONALNumber of dimensions in a rendered image. Used for identifying codes where a two-dimensional slice is assumed.- See Also:
-
X_DIMENSION
protected static final int X_DIMENSIONThe dimensions of x and y axes. Static constants for now, may become configurable fields in the future.- See Also:
-
Y_DIMENSION
protected static final int Y_DIMENSIONThe dimensions of x and y axes. Static constants for now, may become configurable fields in the future.- See Also:
-
readExtent
The area to read in unit of the full coverage (without subsampling). This is the intersection between user-specified domain and the sourceTiledGridResourcedomain, expanded to an integer number of tiles. -
forceTileSize
private final boolean forceTileSizeWhether to force thereadExtenttile intersection to thetileSize. This is relevant only for the last column of tile matrix, because those tiles may be truncated if the image size is not a multiple of tile size. It is usually necessary to read those tiles fully anyway because otherwise, the pixels read from the storage would not be aligned with the pixels stored in theRaster. However, there is a few exceptions where the read extent should not be forced to the tile size:- If the image is untiled, then the
TiledGridResource.Subsetconstructor assumes that only the requested region of the tile will be read. - If the tile is truncated on the storage as well (note: this is rare. GeoTIFF for example always stores whole tiles).
In current version this is a flag for the x dimension only. In a future version it could be flags for other dimensions as well (using bitmask) if it appears to be useful.
- If the image is untiled, then the
-
tileSize
private final int[] tileSizeSize of all tiles in the domain of thisTiledGridCoverage, without clipping and subsampling. All coverages created from the sameTiledGridResourcehave the same tile size values. The length of this array is the number of dimensions in the sourceGridExtent. This is often 2 but can also be more. -
tileStrides
private final int[] tileStridesValues by which to multiply each tile coordinates for obtaining the index in the tile vector. The length of this array is the same astileSize. All coverages created from the sameTiledGridResourcehave the same stride values. -
indexOfFirstTile
private final int indexOfFirstTileIndex of the firstTiledGridCoveragetile in a row-major array of tiles. This is the value to add to the index computed withtileStridesbefore to access vector elements. -
tmcOfFirstTile
private final long[] tmcOfFirstTileThe Tile Matrix Coordinates (TMC) of the first tile. This is the value to subtract from tile indices computed from pixel coordinates.- See Also:
-
subsampling
private final int[] subsamplingConversion from pixel coordinates in this (potentially subsampled) coverage to pixel coordinates in the resource coverage at full resolution. The conversion from (x, y) to (x′, y′) is as below, where s are subsampling factors and t are subsampling offsets:- x′ = s₀⋅x + t₀
- y′ = s₁⋅y + t₁
-
subsamplingOffsets
private final int[] subsamplingOffsetsConversion from pixel coordinates in this (potentially subsampled) coverage to pixel coordinates in the resource coverage at full resolution. The conversion from (x, y) to (x′, y′) is as below, where s are subsampling factors and t are subsampling offsets:- x′ = s₀⋅x + t₀
- y′ = s₁⋅y + t₁
-
includedBands
protected final int[] includedBandsIndices ofTiledGridResourcebands which have been retained for inclusion in thisTiledGridCoverage, in strictly increasing order. An "included" band is stored in memory but not necessarily visible to the user, because theSampleModelcan be configured for ignoring some bands. This array isnullif all bands shall be included.If the user specified bands out of order, the change of band order is taken in account by the sample
model. ThisincludedBandsarray does not apply any change of order for making sequential readings easier. -
rasters
Cache of rasters read by thisTiledGridCoverage. This cache may be shared with other coverages created for the sameTiledGridResourceresource. For each value, the rasterminXandminYvalues can be anything, depending whichTiledGridCoveragewas first to load the tile. -
model
The sample model for all rasters. The width and height of this sample model are the two first elements oftileSizedivided by subsampling and clipped to the domain. If user requested to read only a subset of the bands, then this sample model is already the subset. -
colors
The Java2D color model for images rendered from this coverage. -
fillValue
The value to use for filling empty spaces in rasters, ornullif zero. -
deferredTileReading
private final boolean deferredTileReadingWhether the reading of tiles is deferred toRenderedImage.getTile(int, int)time.
-
-
Constructor Details
-
TiledGridCoverage
Creates a new tiled grid coverage. All parameters should have been validated before this call.- Parameters:
subset- description of theTiledGridResourcesubset to cover.- Throws:
ArithmeticException- if the number of tiles overflows 32 bits integer arithmetic.
-
-
Method Details
-
getIdentifier
protected abstract org.opengis.util.GenericName getIdentifier()Returns a unique name that identifies this coverage. The name shall be unique in theTileMatrixSet.- Returns:
- an human-readable identification of this coverage.
-
getLocale
Returns the locale for error messages, ornullfor the default.- Returns:
- the locale for warning or error messages, or
nullif unspecified.
-
getTileSize
protected final int getTileSize(int dimension) Returns the size of all tiles in the domain of thisTiledGridCoverage, without clipping and subsampling.- Parameters:
dimension- dimension for which to get tile size.- Returns:
- tile size in the given dimension, without clipping and subsampling.
-
getSubsampling
protected final int getSubsampling(int dimension) Returns the subsampling in the given dimension.- Parameters:
dimension- dimension for which to get subsampling.- Returns:
- subsampling as a value ≥ 1.
-
toFullResolution
private long toFullResolution(long coordinate, int dimension) Converts a cell coordinate from thisTiledGridCoveragecoordinate space to full resolution. This method removes the subsampling effect. Note that since thisTiledGridCoverageuses the same coordinate space thanTiledGridResource, the converted coordinates should be valid in the full resource as well.- Parameters:
coordinate- coordinate in thisTiledGridCoveragedomain.dimension- dimension of the coordinate.- Returns:
- coordinate in this
TiledGridCoverageas if no subsampling was applied. - Throws:
ArithmeticException- if the coordinate cannot be represented as a long integer.
-
toSubsampledPixel
private long toSubsampledPixel(long coordinate, int dimension) Converts a cell coordinate fromTiledGridResourcespace toTiledGridCoveragecoordinate. This is the converse oftoFullResolution(long, int). Note that there is a possible accuracy lost.- Parameters:
coordinate- coordinate in theTiledGridResourcedomain.dimension- dimension of the coordinate.- Returns:
- coordinates in this subsampled
TiledGridCoveragedomain. - Throws:
ArithmeticException- if the coordinate cannot be represented as a long integer.
-
toTileMatrixCoordinate
private long toTileMatrixCoordinate(long coordinate, int dimension) Converts a cell coordinate from thisTiledGridCoveragecoordinate space to the Tile Matrix Coordinate (TMC) of the tile which contains that cell. The TMC is relative to the fullTiledGridResource, i.e. without subtraction oftmcOfFirstTile.- Parameters:
coordinate- coordinates in thisTiledGridCoveragedomain.dimension- dimension of the coordinate.- Returns:
- Tile Matrix Coordinate (TMC) of the tile which contains the specified cell.
- Throws:
ArithmeticException- if the coordinate cannot be represented as an integer.
-
getPixelsPerElement
protected final int getPixelsPerElement()Returns the number of pixels in a single bank element. This is usually 1, except forMultiPixelPackedSampleModelwhich packs many pixels in a single bank element. This value is a power of 2 accordingMultiPixelPackedSampleModelspecification.Note: this is "pixels per element", not "samples per element". It makes a difference in theSinglePixelPackedSampleModelcase, for which this method returns 1 (by contrast a "samples per element" would give a value greater than 1). But this value can nevertheless be understood as a "samples per element" value where only one band is considered at a time.- Returns:
- number of pixels in a single bank element. Usually 1.
- See Also:
-
getPixelsPerElement
Implementation ofgetPixelsPerElement().- Parameters:
model- the sample model from which to infer the number of pixels per bank element.- Returns:
- number of pixels in a single bank element. Usually 1.
-
render
Returns a two-dimensional slice of grid data as a rendered image.- Specified by:
renderin classGridCoverage- Parameters:
sliceExtent- a subspace of this grid coverage extent, ornullfor the whole image.- Returns:
- the grid slice as a rendered image. Image location is relative to
sliceExtent.
-
createCacheKey
Creates the key to use for caching the tile at given index. -
readTiles
protected abstract Raster[] readTiles(TiledGridCoverage.AOI iterator) throws IOException, DataStoreException Returns all tiles in the given area of interest. Tile indices are relative to thisTiledGridCoverage: (0,0) is the tile in the upper-left corner of thisTiledGridCoverage(not necessarily the upper-left corner of the image in theTiledGridResource). TheRaster.getMinX()andgetMinY()coordinates of returned rasters shall start at the giveniterator.offsetAOIvalues.This method must be thread-safe. It is implementer responsibility to ensure synchronization, for example using
AbstractResource.getSynchronizationLock().- Parameters:
iterator- an iterator over the tiles that intersect the Area Of Interest specified by user.- Returns:
- tiles decoded from the
TiledGridResource. - Throws:
IOException- if an I/O error occurred.DataStoreException- if a logical error occurred.RuntimeException- if the Java2D image cannot be created for another reason (too many exception types to list them all).
-