Class CoverageUtilities


  • public class CoverageUtilities
    extends Object
    A set of utilities methods for the Grid Coverage package. Those methods are not really rigorous; many of them should be seen as temporary implementations.
    Author:
    Simone Giannecchini, GeoSolutions
    • Method Detail

      • prepareROI

        public static ROI prepareROI​(Geometry roi,
                                     AffineTransform mt2d)
                              throws ProcessException
        Utility method for transforming a geometry ROI into the raster space, using the provided affine transformation.
        Parameters:
        roi - a Geometry in model space.
        mt2d - an AffineTransform that maps from raster to model space. This is already referred to the pixel corner.
        Returns:
        a ROI suitable for using with JAI.
        Throws:
        ProcessException - in case there are problems with ivnerting the provided AffineTransform. Very unlikely to happen.
      • createFeatureType

        public static SimpleFeatureType createFeatureType​(GridCoverage2D gc2d,
                                                          Class<? extends Geometry> geometryClass)
        Creates a SimpleFeatureType that exposes a coverage as a collections of feature points, mapping the centre of each pixel as a point plus all the bands as attributes.

        The FID is the long that combines x+y*width.

        Parameters:
        gc2d - the GridCoverage2D to wrap.
        geometryClass - the class for the geometry.
        Returns:
        a SimpleFeatureType or null in case we are unable to wrap the coverage
      • createRange

        public static <T extends Number> Range createRange​(T minValue,
                                                           boolean minIncluded,
                                                           T maxValue,
                                                           boolean maxIncluded)
        Static create method. This just relieves the tedium of having to call create RangeFactory create method.
        Type Parameters:
        T - value type
        Parameters:
        minValue - the lower bound; passing null for this parameter means an open lower bound; for Float or Double types, the relevant NEGATIVE_INFINITY value can also be used.
        minIncluded - true if the lower bound is to be included in the range; false to exclude the lower bound; overridden to be false if the lower bound is open
        maxValue - the upper bound; passing null for this parameter means an open upper bound; for Float or Double types, the relevant NEGATIVE_INFINITY value can also be used.
        maxIncluded - true if the upper bound is to be included in the range; false to exclude the upper bound; overridden to be false if the upper bound is open
        Returns:
        the new instance
      • getRangeLookupTable

        public static RangeLookupTable getRangeLookupTable​(List<Range> classificationRanges,
                                                           Number noDataValue)
      • getRangeLookupTable

        public static RangeLookupTable getRangeLookupTable​(List<Range> classificationRanges,
                                                           Number noDataValue,
                                                           Class clazz)
      • getRangeLookupTable

        public static RangeLookupTable getRangeLookupTable​(List<Range> classificationRanges,
                                                           int[] outputPixelValues,
                                                           Number noDataValue)
      • getRangeLookupTable

        public static RangeLookupTable getRangeLookupTable​(List<Range> classificationRanges,
                                                           int[] outputPixelValues,
                                                           Number noDataValue,
                                                           Class<? extends Number> clazz)
      • getRangeLookupTable

        public static RangeLookupTable getRangeLookupTable​(List<Range> classificationRanges,
                                                           int[] outputPixelValues,
                                                           Number noDataValue,
                                                           int transferType)
        Setup lookup table from classification ranges.
        Parameters:
        classificationRanges -
        outputPixelValues -
        noDataValue -
        transferType -
        Returns:
        lookup table
      • getRegionParamsFromGridCoverage

        public static HashMap<String,​Double> getRegionParamsFromGridCoverage​(GridCoverage2D gridCoverage)
        Get the parameters of the region covered by the coverage.
        Parameters:
        gridCoverage - the coverage.
        Returns:
        the map of parameters. ( NORTH and the other static vars can be used to retrieve them.
      • getNoDataAsList

        public static List<RangeDouble> getNoDataAsList​(GridCoverage2D coverage)
        Retrieves the no data ranges for a given grid coverage.
        Parameters:
        coverage - the grid coverage to extract nodata ranges from
        Returns:
        a list of no data ranges, or null if no nodata ranges are found
      • crop

        public static GridCoverage2D crop​(GridCoverage2D coverage,
                                          ReferencedEnvelope geometryEnvelope)
        Crops a given grid coverage to the specified geometry envelope using a coverage crop operation.
        Parameters:
        coverage - The source grid coverage to be cropped
        geometryEnvelope - The envelope defining the crop region
        Returns:
        A new GridCoverage2D cropped to the specified envelope
      • getSimplifiedRoiGeometry

        public static ROI getSimplifiedRoiGeometry​(GridCoverage2D coverage,
                                                   Geometry geometry)
                                            throws TransformException
        Converts a given geometry to a simplified Region of Interest (ROI) in raster space for a given grid coverage.
        Parameters:
        coverage - The grid coverage defining the raster transformation context
        geometry - The original geometry to be transformed and simplified
        Returns:
        A simplified ROI geometry suitable for raster processing
        Throws:
        TransformException - If the geometry transformation fails