org.geotools.resources.coverage
Class CoverageUtilities

java.lang.Object
  extended by org.geotools.resources.coverage.CoverageUtilities

public final class CoverageUtilities
extends java.lang.Object

A set of utilities methods for the Grid Coverage package. Those methods are not really rigorous; must of them should be seen as temporary implementations.

Since:
2.4
Version:
$Id: CoverageUtilities.java 35374 2010-05-05 14:41:09Z danieleromagnoli $
Author:
Martin Desruisseaux (IRD), Simone Giannecchini

Method Summary
static boolean checkEmptySourceRegion(javax.imageio.ImageReadParam readParameters, java.awt.Rectangle dimensions)
          Checks that the provided dimensions when intersected with the source region used by the provided ImageReadParam instance does not result in an empty Rectangle.
static double[] getBackgroundValues(GridCoverage2D coverage)
          Retrieves a best guess for the sample value to use for background, inspecting the categories of the provided GridCoverage2D.
static org.opengis.referencing.crs.CoordinateReferenceSystem getCRS2D(org.opengis.coverage.Coverage coverage)
          Returns a two-dimensional CRS for the given coverage.
static Envelope2D getEnvelope2D(org.opengis.coverage.Coverage coverage)
          Returns a two-dimensional envelope for the given coverage.
static org.opengis.referencing.crs.CoordinateReferenceSystem getHorizontalCRS(org.opengis.coverage.Coverage coverage)
          Returns a two-dimensional horizontal CRS for the given coverage.
static double[] getResolution(java.awt.geom.AffineTransform gridToCRS)
          Computes the resolutions for the provided "grid to world" transformation The returned resolution array is of length of 2.
static int getVisibleBand(java.lang.Object image)
          Returns the visible band in the specified RenderedImage or PropertySource.
static boolean hasRenderingCategories(org.opengis.coverage.grid.GridCoverage gridCoverage)
          Returns true if the provided GridCoverage has Category objects with a real transformation.
static boolean hasTransform(org.opengis.coverage.SampleDimension[] sampleDimensions)
          Returns true if at least one of the specified sample dimensions has a sample to geophysics transform which is not the identity transform.
static boolean isScaleTranslate(org.opengis.referencing.operation.MathTransform transform, double EPS)
          Checks if the transformation is a pure scale/translate instance (using the provided tolerance factor)
static boolean isSimpleGridToWorldTransform(java.awt.geom.AffineTransform gridToCRS, double EPS)
          Tries to estimate if the supplied affine transform is either a scale and translate transform or if it contains a rotations which is an integer multiple of PI/2.
static ViewType preferredViewAfterOperation(GridCoverage2D coverage)
          The preferred view in which to returns the coverage after the operation.
static ViewType preferredViewForOperation(GridCoverage2D coverage, javax.media.jai.Interpolation interpolation, boolean hasFilter, java.awt.RenderingHints hints)
          General purpose method used in various operations for GridCoverage2D to help with taking decisions on how to treat coverages with respect to their ColorModel.
static boolean uses(org.opengis.coverage.grid.GridCoverage coverage, java.awt.image.RenderedImage image)
          Returns true if the specified grid coverage or any of its source uses the following image.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getCRS2D

public static org.opengis.referencing.crs.CoordinateReferenceSystem getCRS2D(org.opengis.coverage.Coverage coverage)
                                                                      throws org.opengis.referencing.operation.TransformException
Returns a two-dimensional CRS for the given coverage. This method performs a best effort; the returned CRS is not garanteed to be the most appropriate one.

Parameters:
coverage - The coverage for which to obtains a two-dimensional CRS.
Returns:
The two-dimensional CRS.
Throws:
org.opengis.referencing.operation.TransformException - if the CRS can't be reduced to two dimensions.

getHorizontalCRS

public static org.opengis.referencing.crs.CoordinateReferenceSystem getHorizontalCRS(org.opengis.coverage.Coverage coverage)
                                                                              throws org.opengis.referencing.operation.TransformException
Returns a two-dimensional horizontal CRS for the given coverage. This method performs a best effort; the returned CRS is not garanteed to succed.

Parameters:
coverage - The coverage for which to obtains a two-dimensional horizontal CRS.
Returns:
The two-dimensional horizontal CRS.
Throws:
org.opengis.referencing.operation.TransformException - if the CRS can't be reduced to two dimensions.

getEnvelope2D

public static Envelope2D getEnvelope2D(org.opengis.coverage.Coverage coverage)
                                throws org.opengis.geometry.MismatchedDimensionException
Returns a two-dimensional envelope for the given coverage. This method performs a best effort; the returned envelope is not garanteed to be the most appropriate one.

Parameters:
coverage - The coverage for which to obtains a two-dimensional envelope.
Returns:
The two-dimensional envelope.
Throws:
org.opengis.geometry.MismatchedDimensionException - if the envelope can't be reduced to two dimensions.

getBackgroundValues

public static double[] getBackgroundValues(GridCoverage2D coverage)
Retrieves a best guess for the sample value to use for background, inspecting the categories of the provided GridCoverage2D.

Parameters:
coverage - to use for guessing background values.
Returns:
an array of double values to use as a background.

hasRenderingCategories

public static boolean hasRenderingCategories(org.opengis.coverage.grid.GridCoverage gridCoverage)
Returns true if the provided GridCoverage has Category objects with a real transformation.

Common use case for this method is understanding if a GridCoverage has an accompanying Geophysics or non-Geophysics view, which means a dicotomy between the coverage with the "real" data and the coverage with the rendered version of the original data exists. An example is when you have raw data whose data type is float and you want to render them using a palette. You usually do this by specifying a set of Category object which will map some intervals of the raw data to some specific colors. The rendered version that we will create using the method GridCoverage2D#geophysics(false) will be backed by a RenderedImage with an IndexColorModel representing the colors provided in the Categories.

Parameters:
gridCoverage - to check for the existence of categories with tranformations between original data and their rendered counterpart.
Returns:
false if this coverage has only a single view associated with it, true otherwise.

hasTransform

public static boolean hasTransform(org.opengis.coverage.SampleDimension[] sampleDimensions)
Returns true if at least one of the specified sample dimensions has a sample to geophysics transform which is not the identity transform.


uses

public static boolean uses(org.opengis.coverage.grid.GridCoverage coverage,
                           java.awt.image.RenderedImage image)
Returns true if the specified grid coverage or any of its source uses the following image.


getVisibleBand

public static int getVisibleBand(java.lang.Object image)
Returns the visible band in the specified RenderedImage or PropertySource. This method fetch the "GC_VisibleBand" property. If this property is undefined, then the visible band default to the first one.

Parameters:
image - The image for which to fetch the visible band, or null.
Returns:
The visible band.

preferredViewForOperation

public static ViewType preferredViewForOperation(GridCoverage2D coverage,
                                                 javax.media.jai.Interpolation interpolation,
                                                 boolean hasFilter,
                                                 java.awt.RenderingHints hints)
General purpose method used in various operations for GridCoverage2D to help with taking decisions on how to treat coverages with respect to their ColorModel.

The need for this method arose in consideration of the fact that applying most operations on coverage whose ColorModel is an instance of IndexColorModel may lead to unpredictable results depending on the applied Interpolation (think about applying "Scale" with InterpolationBilinear on a non-geophysics GridCoverage2D with an IndexColorModel) or more simply on the operation itself ("SubsampleAverage" cannot be applied at all on a GridCoverage2D backed by an IndexColorModel).

This method suggests the actions to take depending on the structure of the provided GridCoverage2D, the provided Interpolation and if the operation uses a filter or not (this is useful for operations like SubsampleAverage or FilteredSubsample).

In general the idea is as follows: If the original coverage is backed by a RenderedImage with an IndexColorModel, we have the following cases:

A special case is when we want to apply an operation on the geophysics view of a coverage that does not involve high order interpolation or filters. In this case we suggest to apply the operation on the non-geophysics view, which is usually much faster. Users may ignore this advice.

Parameters:
coverage - The coverage to check for the action to take.
interpolation - The interpolation to use for the action to take, or null if none.
hasFilter - true if the operation we will apply is going to use a filter.
hints - The hints to use when applying a certain operation.
Returns:
ViewType.SAME if nothing has to be done on the provided coverage, ViewType.PHOTOGRAPHIC if a color expansion has to be provided, ViewType.GEOPHYSICS if we need to employ the geophysics view of the provided coverage, ViewType.NATIVE if we suggest to employ the native (usually packed) view of the provided coverage.
Since:
2.5

preferredViewAfterOperation

public static ViewType preferredViewAfterOperation(GridCoverage2D coverage)
The preferred view in which to returns the coverage after the operation. This method returns a view that match the current state of the given coverage.

Parameters:
coverage - The source coverage before the operation.
Returns:
The suggested view, or ViewType.SAME if this method doesn't have any suggestion.
Since:
2.5

isScaleTranslate

public static boolean isScaleTranslate(org.opengis.referencing.operation.MathTransform transform,
                                       double EPS)
Checks if the transformation is a pure scale/translate instance (using the provided tolerance factor)

Parameters:
transform - The MathTransform to check.
EPS - The tolerance factor.
Returns:
true if the provided transformation is a simple scale and translate, false otherwise.

getResolution

public static double[] getResolution(java.awt.geom.AffineTransform gridToCRS)
Computes the resolutions for the provided "grid to world" transformation The returned resolution array is of length of 2.

Parameters:
gridToCRS - The grid to world transformation.

isSimpleGridToWorldTransform

public static boolean isSimpleGridToWorldTransform(java.awt.geom.AffineTransform gridToCRS,
                                                   double EPS)
Tries to estimate if the supplied affine transform is either a scale and translate transform or if it contains a rotations which is an integer multiple of PI/2.

Parameters:
gridToCRS - an instance of AffineTransform to check against.
EPS - tolerance value for comparisons.
Returns:
true if this transform is "simple", false otherwise.

checkEmptySourceRegion

public static boolean checkEmptySourceRegion(javax.imageio.ImageReadParam readParameters,
                                             java.awt.Rectangle dimensions)
Checks that the provided dimensions when intersected with the source region used by the provided ImageReadParam instance does not result in an empty Rectangle. Finally, in case the region intersection is not empty, set it as new source region for the provided ImageReadParam.

Input parameters cannot be null.

Parameters:
readParameters - an instance of ImageReadParam for which we want to check the source region element.
dimensions - an instance of Rectangle to use for the check.
Returns:
true if the intersection is not empty, false otherwise.


Copyright © 1996-2010 Geotools. All Rights Reserved.