Class GridCoverageRenderer


  • public final class GridCoverageRenderer
    extends Object
    A helper class for rendering GridCoverage objects.
    Author:
    Simone Giannecchini, GeoSolutions SAS, Andrea Aime, GeoSolutions SAS, Alessio Fabiani, GeoSolutions SAS
    • Field Detail

      • PARENT_COVERAGE_PROPERTY

        public static final String PARENT_COVERAGE_PROPERTY
        See Also:
        Constant Field Values
      • PADDING

        public static final Hints.Key PADDING
        Hint's KEY specifying a custom padding
    • Constructor Detail

      • GridCoverageRenderer

        public GridCoverageRenderer​(CoordinateReferenceSystem destinationCRS,
                                    Envelope envelope,
                                    Rectangle screenSize,
                                    AffineTransform worldToScreen)
                             throws TransformException,
                                    NoninvertibleTransformException
        Creates a new GridCoverageRenderer object.
        Parameters:
        destinationCRS - the CRS of the GridCoverage2D to render.
        envelope - delineating the area to be rendered.
        screenSize - at which we want to render the source GridCoverage2D.
        worldToScreen - if not null and if it contains a rotation, this Affine Transform is used directly to convert from world coordinates to screen coordinates. Otherwise, a standard GridToEnvelopeMapper is used to calculate the affine transform.
        Throws:
        TransformException
        NoninvertibleTransformException
      • GridCoverageRenderer

        public GridCoverageRenderer​(CoordinateReferenceSystem destinationCRS,
                                    Envelope envelope,
                                    Rectangle screenSize,
                                    AffineTransform worldToScreen,
                                    RenderingHints newHints)
                             throws TransformException,
                                    NoninvertibleTransformException
        Creates a new GridCoverageRenderer object.
        Parameters:
        destinationCRS - the CRS of the GridCoverage2D to render.
        envelope - delineating the area to be rendered.
        screenSize - at which we want to render the source GridCoverage2D.
        worldToScreen - if not null and if it contains a rotation, this Affine Transform is used directly to convert from world coordinates to screen coordinates. Otherwise, a standard GridToEnvelopeMapper is used to calculate the affine transform.
        newHints - RenderingHints to control this rendering process.
        Throws:
        TransformException
        NoninvertibleTransformException
    • Method Detail

      • setWrapEnabled

        public void setWrapEnabled​(boolean wrapEnabled)
        Enables/disable map wrapping (active only when rendering off a GridCoverage2DReader and when advanced projection handling has been enabled too)
      • isWrapEnabled

        public boolean isWrapEnabled()
        Returns true if map wrapping is enabled (active only when rendering off a GridCoverage2DReader and when advanced projection handling has been enabled too)
      • setAdvancedProjectionHandlingEnabled

        public void setAdvancedProjectionHandlingEnabled​(boolean enabled)
        Enables/disables advanced projection handling (read all areas needed to make up the requested map, cut them to areas where reprojection makes sense, and so on). Works only when rendering off a GridCoverage2DReader.
      • isAdvancedProjectionHandlingEnabled

        public boolean isAdvancedProjectionHandlingEnabled()
        Tests if advanced projection handling is enabled (read all areas needed to make up the requested map, cut them to areas where reprojection makes sense, and so on). Works only when rendering off a GridCoverage2DReader.
      • renderImage

        public RenderedImage renderImage​(GridCoverage2D gridCoverage,
                                         RasterSymbolizer symbolizer,
                                         double[] bkgValues)
                                  throws Exception
        Turns the coverage into a rendered image applying the necessary transformations and the symbolizer

        Builds a (RenderedImage, AffineTransform) pair that can be used for rendering onto a Graphics2D or as the basis to build a final image. Will return null if there is nothing to render.

        Returns:
        The transformed image, or null if the coverage does not lie within the rendering bounds
        Throws:
        Exception
      • renderImage

        public RenderedImage renderImage​(GridCoverage2D gridCoverage,
                                         RasterSymbolizer symbolizer,
                                         Interpolation interpolation,
                                         Color background,
                                         int tileSizeX,
                                         int tileSizeY)
                                  throws FactoryException,
                                         TransformException,
                                         NoninvertibleTransformException
        Turns the coverage into a rendered image applying the necessary transformations and the symbolizer
        Returns:
        The transformed image, or null if the coverage does not lie within the rendering bounds
        Throws:
        FactoryException
        TransformException
        NoninvertibleTransformException
      • paint

        public void paint​(Graphics2D graphics,
                          GridCoverage2D gridCoverage,
                          RasterSymbolizer symbolizer)
                   throws Exception
        Paint this grid coverage. The caller must ensure that graphics has an affine transform mapping "real world" coordinates in the coordinate system given by
        Parameters:
        graphics - the Graphics2D context in which to paint.
        Throws:
        UnsupportedOperationException - if the transformation from grid to coordinate system in the GridCoverage is not an AffineTransform
        Exception
      • paint

        public void paint​(Graphics2D graphics,
                          GridCoverage2D gridCoverage,
                          RasterSymbolizer symbolizer,
                          double[] bkgValues)
                   throws Exception
        Paint this grid coverage. The caller must ensure that graphics has an affine transform mapping "real world" coordinates in the coordinate system given by #getCoordinateSystem.
        Parameters:
        graphics - the Graphics2D context in which to paint.
        Throws:
        UnsupportedOperationException - if the transformation from grid to coordinate system in the GridCoverage is not an AffineTransform
        Exception
      • paint

        public void paint​(Graphics2D graphics,
                          GridCoverage2DReader gridCoverageReader,
                          GeneralParameterValue[] readParams,
                          RasterSymbolizer symbolizer,
                          Interpolation interpolation,
                          Color background)
                   throws Exception
        Paint the coverage read from the reader (using advanced projection handling). The caller must ensure that graphics has an affine transform mapping "real world" coordinates in the coordinate system given by #getCoordinateSystem.
        Parameters:
        graphics - the Graphics2D context in which to paint.
        Throws:
        UnsupportedOperationException - if the transformation from grid to coordinate system in the GridCoverage is not an AffineTransform
        Exception
      • setupSymbolizerForBandsSelection

        public static RasterSymbolizer setupSymbolizerForBandsSelection​(RasterSymbolizer symbolizer)
        Takes into account that the band selection has been delegated down to the reader by producing a new channel selection
      • isBandsSelectionApplicable

        public static boolean isBandsSelectionApplicable​(GridCoverageReader reader,
                                                         RasterSymbolizer symbolizer)
        Checks if band selection is present, and can be delegated down to the reader