Class CoverageUtilities


  • public 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.
    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
      • 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)
      • getRangeLookupTableJAIEXT

        public static RangeLookupTable getRangeLookupTableJAIEXT​(List<Range> classificationRanges,
                                                                 int[] outputPixelValues,
                                                                 Number noDataValue,
                                                                 int transferType)
      • 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<Range<Double>> 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