Class CoverageUtilities


  • public final class CoverageUtilities
    extends 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
    Author:
    Martin Desruisseaux (IRD), Simone Giannecchini, GeoSolutions
    • Field Detail

      • NODATA

        public static final InternationalString NODATA
        Public name for standard No Data category.
      • AXES_SWAP

        public static final AffineTransform AXES_SWAP
        Axes transposition for swapping Lat and Lon axes.
      • IDENTITY_TRANSFORM

        public static final AffineTransform IDENTITY_TRANSFORM
        Identity affine transformation.
      • CENTER_TO_CORNER

        public static final AffineTransform CENTER_TO_CORNER
        AffineTransform that can be used to go from an image datum placed at the center of pixels to one that is placed at ULC.
      • CORNER_TO_CENTER

        public static final AffineTransform CORNER_TO_CENTER
        AffineTransform that can be used to go from an image datum placed at the ULC corner of pixels to one that is placed at center.
    • Method Detail

      • getCRS2D

        public static CoordinateReferenceSystem getCRS2D​(Coverage coverage)
                                                  throws 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:
        TransformException - if the CRS can't be reduced to two dimensions.
      • getHorizontalCRS

        public static CoordinateReferenceSystem getHorizontalCRS​(Coverage coverage)
                                                          throws 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:
        TransformException - if the CRS can't be reduced to two dimensions.
      • getEnvelope2D

        public static ReferencedEnvelope getEnvelope2D​(Coverage coverage)
                                                throws 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:
        MismatchedDimensionException - if the envelope can't be reduced to two dimensions.
      • getNoDataProperty

        public static NoDataContainer getNoDataProperty​(GridCoverage2D coverage)
        Utility method for extracting NoData property from input GridCoverage2D.
        Returns:
        A NoDataContainer object containing input NoData definition
      • getROIProperty

        public static ROI getROIProperty​(GridCoverage2D coverage)
        Utility method for extracting ROI property from input GridCoverage2D.
        Returns:
        A ROI object
      • setNoDataProperty

        public static void setNoDataProperty​(Map<String,​Object> properties,
                                             Object noData)
        Utility method for setting NoData to the input Map
        Parameters:
        properties - Map where the nodata will be set
        noData - May be a Range, double[], double or NoDataContainer
      • setROIProperty

        public static void setROIProperty​(Map<String,​Object> properties,
                                          ROI roi)
        Utility method for setting ROI to the input Map
        Parameters:
        properties - Map where the ROI will be set
        roi - ROI instance to set
      • 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.
      • uses

        public static boolean uses​(GridCoverage coverage,
                                   RenderedImage image)
        Returns true if the specified grid coverage or any of its source uses the following image.
      • getVisibleBand

        public static int getVisibleBand​(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.
      • isScaleTranslate

        public static boolean isScaleTranslate​(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​(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​(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​(ImageReadParam readParameters,
                                                     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.
      • getMosaicThreshold

        public static double getMosaicThreshold​(int dataType)
        Returns a suitable threshold depending on the DataBuffer type.

        Remember that the threshold works with >=.

        Parameters:
        dataType - to create a low threshold for.
        Returns:
        a minimum threshold value suitable for this data type.
      • suggestNoDataValue

        public static Number suggestNoDataValue​(int dataType)
        Returns a suitable no data value depending on the DataBuffer type.
        Parameters:
        dataType - to create a low threshold for.
        Returns:
        a no data value suitable for this data type.
      • loadPropertiesFromURL

        public static Properties loadPropertiesFromURL​(URL propsURL)
        Extract Properties from a specified URL