Package org.apache.sis.coverage.grid
Class ResampledGridCoverage
java.lang.Object
org.apache.sis.coverage.BandedCoverage
org.apache.sis.coverage.grid.GridCoverage
org.apache.sis.coverage.grid.DerivedGridCoverage
org.apache.sis.coverage.grid.ResampledGridCoverage
A multi-dimensional grid coverage where each two-dimensional slice is the resampling
of data from another grid coverage. This class is used when the resampling cannot be
stored in a
GridCoverage2D.- Since:
- 1.1
- Version:
- 1.3
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.sis.coverage.grid.GridCoverage
GridCoverage.Evaluator, GridCoverage.Lazy -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intThe 2 constant for identifying code specific to the two-dimensional case.private final ImageProcessorThe image processor to use for resampling operations.private final intValue ofInterpolation.getSupportSize().private final intValue ofInterpolation.getSupportSize().private final org.opengis.referencing.operation.MathTransformThe transform from cell coordinates in this coverage to cell coordinates in source coverage.private final org.opengis.referencing.operation.MathTransformThe transform from cell coordinates in this coverage to cell coordinates in source coverage.private final long[]Mapping from dimensions in thisResampledGridCoverageto dimensions in the source coverage.Fields inherited from class org.apache.sis.coverage.grid.DerivedGridCoverage
sourceFields inherited from class org.apache.sis.coverage.grid.GridCoverage
gridGeometry -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateResampledGridCoverage(GridCoverage source, GridGeometry domain, org.opengis.referencing.operation.MathTransform toSourceCorner, org.opengis.referencing.operation.MathTransform toSourceCenter, CoordinateOperationFinder changeOfCRS, ImageProcessor processor) Creates a new grid coverage which will be the resampling of the given source. -
Method Summary
Modifier and TypeMethodDescription(package private) static GridCoveragecreate(GridCoverage source, GridGeometry target, ImageProcessor processor, boolean allowOperationReplacement) Implementation ofGridCoverageProcessor.resample(GridCoverage, GridGeometry).(package private) static booleanequivalent(GridGeometry sourceGG, GridGeometry targetGG) Checks if two grid geometries are equal, ignoring unspecified properties.private static long[]findDependentDimensions(org.opengis.referencing.operation.MathTransform mt, GridGeometry domain) Returns the set of target dimensions that depend on each source dimension.private static long[]getIntegerTranslation(org.opengis.referencing.operation.MathTransform toSource) If the given transform is a translation and all translation terms are integers, returns the translation.private static booleanisDefined(GridGeometry sourceGG, GridGeometry targetGG, int property) Returns whether the given property is defined in both grid geometries.render(GridExtent sliceExtent) Returns a two-dimensional slice of resampled grid data as a rendered image.private GridCoveragespecialize(boolean allowGeometryReplacement, boolean allowOperationReplacement) If this coverage can be represented as aGridCoverage2Dinstance, returns such instance.private static GridExtenttargetExtent(GridExtent source, org.opengis.referencing.operation.MathTransform cornerToCRS, org.opengis.referencing.operation.MathTransform crsToGrid, boolean center) Computes a target grid extent by transforming the source grid extent.Methods inherited from class org.apache.sis.coverage.grid.DerivedGridCoverage
evaluator, getBandType, IsNotRepleacable, toTreeMethods inherited from class org.apache.sis.coverage.grid.GridCoverage
appendDataLayout, convert, createConvertedValues, forConvertedValues, getCoordinateReferenceSystem, getEnvelope, getGridGeometry, getSampleDimensions, toString
-
Field Details
-
BIDIMENSIONAL
private static final int BIDIMENSIONALThe 2 constant for identifying code specific to the two-dimensional case.- See Also:
-
toSourceCorner
private final org.opengis.referencing.operation.MathTransform toSourceCornerThe transform from cell coordinates in this coverage to cell coordinates in source coverage. Note that an offset may exist between cell coordinates and pixel coordinates, so some translations may need to be concatenated with this transform on an image-by-image basis. -
toSourceCenter
private final org.opengis.referencing.operation.MathTransform toSourceCenterThe transform from cell coordinates in this coverage to cell coordinates in source coverage. Note that an offset may exist between cell coordinates and pixel coordinates, so some translations may need to be concatenated with this transform on an image-by-image basis. -
toSourceDimensions
private final long[] toSourceDimensionsMapping from dimensions in thisResampledGridCoverageto dimensions in the source coverage. The mapping is represented by a bitmask. For a target dimension i,toSourceDimensions[i]has a bit set to 1 for all source dimensions used in the computation of that target dimension. This array may benullif the mapping cannot be computed or if it is not needed. -
imageProcessor
The image processor to use for resampling operations. Its configuration shall not be modified because this processor may be shared by different grid coverages. -
supportSizeX
private final int supportSizeXValue ofInterpolation.getSupportSize(). This is 1 for nearest-neighbor, 2 for bilinear, 4 for bicubic interpolation. -
supportSizeY
private final int supportSizeYValue ofInterpolation.getSupportSize(). This is 1 for nearest-neighbor, 2 for bilinear, 4 for bicubic interpolation.
-
-
Constructor Details
-
ResampledGridCoverage
private ResampledGridCoverage(GridCoverage source, GridGeometry domain, org.opengis.referencing.operation.MathTransform toSourceCorner, org.opengis.referencing.operation.MathTransform toSourceCenter, CoordinateOperationFinder changeOfCRS, ImageProcessor processor) Creates a new grid coverage which will be the resampling of the given source.- Parameters:
source- the coverage to resample.domain- the grid extent, CRS and conversion from cell indices to CRS.toSourceCorner- transform from cell corner coordinates in this coverage to source coverage.toSourceCenter- transform from cell center coordinates in this coverage to source coverage.changeOfCRS- encapsulate information about the change of CRS.processor- the image processor to use for resampling images.
-
-
Method Details
-
findDependentDimensions
private static long[] findDependentDimensions(org.opengis.referencing.operation.MathTransform mt, GridGeometry domain) Returns the set of target dimensions that depend on each source dimension. For a source dimension i,dependentDimensions[i]is a bitmask with bits set to 1 for each target dimension which require the source dimension i for its calculation.- Parameters:
mt- the transform (mapping pixel centers) for which to determine dimension dependencies.domain- domain of this .- Returns:
- for each source dimension, a bitmask of target dependent dimensions.
May be
nullif the mapping cannot be computed or if it is not needed.
-
getIntegerTranslation
private static long[] getIntegerTranslation(org.opengis.referencing.operation.MathTransform toSource) If the given transform is a translation and all translation terms are integers, returns the translation. Otherwise returnsnull. It does not matter if the given transform istoSourceCenterortoSourceCorner, because those two transforms should be identical when all scale factors are 1. We nevertheless test the two transforms in case one of them has rounding errors. -
specialize
private GridCoverage specialize(boolean allowGeometryReplacement, boolean allowOperationReplacement) throws org.opengis.referencing.operation.TransformException If this coverage can be represented as aGridCoverage2Dinstance, returns such instance. Otherwise returnsthis.- Parameters:
allowGeometryReplacement- whether to allow the replacement of grid geometry in the target coverage.allowOperationReplacement- whether to allow the replacement of this operation by a more efficient one.- Throws:
org.opengis.referencing.operation.TransformException
-
equivalent
Checks if two grid geometries are equal, ignoring unspecified properties. If a geometry has no extent or nogridToCRStransform, the missing property is not compared. Same applies for the grid extent.- Returns:
trueif the two geometries are equal, ignoring unspecified properties.
-
isDefined
Returns whether the given property is defined in both grid geometries.- Parameters:
property- one ofGridGeometryconstants.
-
create
static GridCoverage create(GridCoverage source, GridGeometry target, ImageProcessor processor, boolean allowOperationReplacement) throws org.opengis.util.FactoryException, org.opengis.referencing.operation.TransformException Implementation ofGridCoverageProcessor.resample(GridCoverage, GridGeometry). This method computes the inverse of the transform from Source Grid to Target Grid. That transform will be computed using the following path:Target Grid ⟶ Target CRS ⟶ Source CRS ⟶ Source Grid
If the targetGridGeometryis incomplete, this method provides default values for the missing properties. The following cases may occur:-
User provided no
GridExtent. This method will construct a "grid to CRS" transform preserving (at least approximately) axis directions and resolutions at the point of interest. Then a grid extent will be created with a size large enough for containing the original grid transformed by above Source Grid → Target Grid transform. -
User provided only a
GridExtent. This method will compute an envelope large enough for containing the projected coordinates, then a "grid to CRS" transform will be derived from the grid and the georeferenced envelope with an attempt to preserve axis directions at least approximately. - User provided only a "grid to CRS" transform. This method will transform the projected envelope to "grid units" using the specified transform and create a grid extent large enough to hold the result.
- Parameters:
source- the grid coverage to resample.target- the desired geometry of returned grid coverage. May be incomplete.processor- the processor to use for executing the resample operation on images.allowOperationReplacement- whether to allow the replacement of this operation by a more efficient one.- Returns:
- a grid coverage with the characteristics specified in the given grid geometry.
- Throws:
IncompleteGridGeometryException- if the source grid geometry is missing an information.org.opengis.referencing.operation.TransformException- if some coordinates cannot be transformed to the specified target.org.opengis.util.FactoryException
-
User provided no
-
targetExtent
private static GridExtent targetExtent(GridExtent source, org.opengis.referencing.operation.MathTransform cornerToCRS, org.opengis.referencing.operation.MathTransform crsToGrid, boolean center) throws org.opengis.referencing.operation.TransformException Computes a target grid extent by transforming the source grid extent.Note on rounding mode: calculation of source envelope should useGridRoundingMode.ENCLOSINGfor making sure that we include all needed data. On the opposite, calculation of target envelope should useGridRoundingMode.CONTAINEDfor making sure that we interpolate only values where data are available. However, such "fully contained" mode is often overly strict because a very small rounding error can cause the lost of an image row or column, while using extrapolations for those values produce no perceptible errors. Consequently, this method usesGridRoundingMode.NEARESTas a compromise.- Parameters:
source- the source grid extent to transform.cornerToCRS- transform from source grid corners to target CRS.crsToGrid- transform from target CRS to target grid corners or centers.center- whethercrsToGridmaps cell centers (true) or cell corners (false).- Returns:
- target grid extent.
- Throws:
org.opengis.referencing.operation.TransformException
-
render
Returns a two-dimensional slice of resampled grid data as a rendered image.- Specified by:
renderin classGridCoverage- Parameters:
sliceExtent- a subspace of this grid coverage extent where all dimensions except two have a size of 1 cell. May benullif this grid coverage has only two dimensions with a size greater than 1 cell.- Returns:
- the grid slice as a rendered image. Image location is relative to
sliceExtent. - Throws:
CannotEvaluateException- if this method cannot produce the rendered image.
-