Class OperationJAI

    • Field Detail

      • operation

        protected final OperationDescriptor operation
        The JAI's operation descriptor.
    • Constructor Detail

      • OperationJAI

        public OperationJAI​(String operation)
                     throws OperationNotFoundException
        Constructs a grid coverage operation from a JAI operation name. This convenience constructor fetch the OperationDescriptor from the specified operation name using the default JAI instance.
        Parameters:
        operation - JAI operation name
        Throws:
        OperationNotFoundException - if no JAI descriptor was found for the given name.
      • OperationJAI

        public OperationJAI​(OperationDescriptor operation)
        Constructs a grid coverage operation backed by a JAI operation. The operation descriptor must supports the "rendered" mode (which is the case for most JAI operations).
        Parameters:
        operation - The JAI operation descriptor.
      • OperationJAI

        public OperationJAI​(String operationName,
                            OperationDescriptor operation)
        Constructs a grid coverage operation backed by a JAI operation. The operation descriptor must supports the "rendered" mode (which is the case for most JAI operations).
        Parameters:
        operationName - JAI operation name
        operation - The JAI operation descriptor.
      • OperationJAI

        protected OperationJAI​(OperationDescriptor operation,
                               ParameterDescriptorGroup descriptor)
        Constructs a grid coverage operation backed by a JAI operation. The operation descriptor must supports the "rendered" mode (which is the case for most JAI operations).
        Parameters:
        operation - The JAI operation descriptor.
        descriptor - The OGC parameters descriptor.
    • Method Detail

      • getOperationDescriptor

        protected static OperationDescriptor getOperationDescriptor​(String name)
                                                             throws OperationNotFoundException
        Returns the operation descriptor for the specified JAI operation name. This method uses the default JAI instance and looks for the "rendered" mode.
        Parameters:
        name - The operation name.
        Returns:
        The operation descriptor for the given name.
        Throws:
        OperationNotFoundException - if no JAI descriptor was found for the given name.
        Since:
        2.4
      • prepareParameters

        protected ParameterBlockJAI prepareParameters​(ParameterValueGroup parameters)
        Copies parameter values from the specified ParameterValueGroup to the ParameterBlockJAI, except the sources.

        Note: it would be possible to use ImagingParameters.parameters directly in some occasions. However, we perform an unconditional copy instead because some operations may change the values.

        Parameters:
        parameters - The ParameterValueGroup to be copied.
        Returns:
        A copy of the provided ParameterValueGroup as a JAI block.
        Since:
        2.4
      • resampleToCommonGeometry

        protected void resampleToCommonGeometry​(GridCoverage2D[] sources,
                                                CoordinateReferenceSystem crs2D,
                                                MathTransform2D gridToCrs2D,
                                                Hints hints)
                                         throws InvalidGridGeometryException,
                                                CannotReprojectException
        Resamples all sources grid coverages to the same two-dimensional geometry before to apply the operation. This method is invoked automatically by the doOperation method. Only the two-dimensional part is reprojected (usually the spatial component of a CRS). Extra dimension (if any) are left unchanged. Extra dimensions are typically time axis or depth. Note that extra dimensions are not forced to a common geometry; only the two dimensions that apply to a PlanarImage are. This is because the extra dimensions don't need to be compatible for all operations. For example if a source image is a slice in a time series, a second source image could be a slice in the frequency representation of this time series.

        Subclasses should override this method if they want to specify target grid geometry and coordinate reference system different than the default ones. For example if a subclass wants to force all images to be referenced in a WGS 84 CRS, then it may overrides this method as below:

         protected void resampleToCommonGeometry(...) {
            crs2D = DefaultGeographicCRS.WGS84;
            super.resampleToCommonGeometry(sources, crs2D, gridToCrs2D, hints);
         }
        Parameters:
        sources - The source grid coverages to resample. This array is updated in-place as needed (for example if a grid coverage is replaced by a projected one).
        crs2D - The target coordinate reference system to use, or null for a default one.
        gridToCrs2D - The target "grid to coordinate reference system" transform, or null for a default one.
        hints - The rendering hints, or null if none.
        Throws:
        InvalidGridGeometryException - if a source coverage has an unsupported grid geometry.
        CannotReprojectException - if a grid coverage can't be resampled for some other reason.
      • getQuantitative

        protected static int getQuantitative​(Category[] categories)
        Returns the index of the quantitative category, providing that there is one and only one quantitative category. If categories contains 0, 2 or more quantitative category, then this method returns -1.
        Parameters:
        categories - The categories to test.
        Returns:
        The index of the quantitative category, or -1 if none can be choosen.
        Since:
        2.4
      • deriveCategory

        protected Category deriveCategory​(Category[] categories,
                                          OperationJAI.Parameters parameters)
        Returns the quantitative category for a single sample dimension in the target grid coverage. This method is invoked automatically by the deriveSampleDimension method for each band in the target image. The default implementation creates a default category from the target range of values returned by deriveRange.
        Parameters:
        categories - The quantitative categories from every sources. For unary operations like, this array has a length of 1. For binary operations like "add" and "multiply", this array has a length of 2.
        parameters - Parameters, rendering hints and coordinate reference system to use.
        Returns:
        The quantitative category to use in the destination image, or null if unknown.
      • deriveRange

        protected NumberRange<? extends Number> deriveRange​(NumberRange<? extends Number>[] ranges,
                                                            OperationJAI.Parameters parameters)
        Returns the range of value for a single sample dimension in the target grid coverage. This method is invoked automatically by the deriveCategory method for each band in the target image. Subclasses should override this method in order to compute the target range of values. For example, the "add" operation may implements this method as below:
         double min = ranges[0].getMinimum() + ranges[1].getMinimum();
         double max = ranges[0}.getMaximum() + ranges[1}.getMaximum();
         return new NumberRange(min, max);
         
        Parameters:
        ranges - The range of values from every sources. For unary operations this array has a length of 1. For binary operations like "add" and "multiply", this array has a length of 2.
        parameters - Parameters, rendering hints and coordinate reference system to use.
        Returns:
        The range of values to use in the destination image, or null if unknow.
      • deriveUnit

        protected Unit<?> deriveUnit​(Unit<?>[] units,
                                     OperationJAI.Parameters parameters)
        Returns the unit of data for a single sample dimension in the target grid coverage. This method is invoked automatically by the deriveSampleDimension method for each band in the target image. Subclasses should override this method in order to compute the target units from the source units. For example a "multiply" operation may implement this method as below:
         if (units[0]!=null && units[1]!=null) {
             return units[0].multiply(units[1]);
         } else {
             return super.deriveUnit(units, cs, parameters);
         }
         
        Parameters:
        units - The units from every sources. For unary operations this array has a length of 1. For binary operations like "add" and "multiply", this array has a length of 2.
        parameters - Parameters, rendering hints and coordinate reference system to use.
        Returns:
        The unit of data in the destination image, or null if unknow.
      • deriveName

        protected InternationalString deriveName​(GridCoverage2D[] sources,
                                                 int primarySourceIndex,
                                                 OperationJAI.Parameters parameters)
        Returns a name for the target grid coverage based on the given sources. This method is invoked once by the deriveGridCoverage method. The default implementation returns the operation name followed by the source name between parenthesis, for example "Add(Sea Surface Temperature)".
        Parameters:
        sources - The sources grid coverage.
        primarySourceIndex - The index of what seems to be the primary source, or -1 if none of unknown.
        parameters - Parameters, rendering hints and coordinate reference system to use.
        Returns:
        A name for the target grid coverage.
      • createRenderedImage

        protected RenderedImage createRenderedImage​(ParameterBlockJAI parameters,
                                                    RenderingHints hints)
        Applies the JAI operation. The operation name can be fetch from operation. The JAI instance to use can be fetch from getJAI(java.awt.RenderingHints). The default implementation returns the following:
         getJAI(hints).createNS(operation.getName(), parameters, hints)
         
        Subclasses may override this method in order to invokes a different JAI operation according the parameters.
        Parameters:
        parameters - The parameters to be given to JAI.
        hints - The rendering hints to be given to JAI.
        Returns:
        The result of JAI operation using the given parameters and hints.
      • getJAI

        public static final JAI getJAI​(RenderingHints hints)
        Returns the JAI instance to use for operations on RenderedImage. If no JAI instance is defined for the Hints.JAI_INSTANCE key, then the default instance is returned.
        Parameters:
        hints - The rendering hints, or null if none.
        Returns:
        The JAI instance to use (never null).
      • equals

        public boolean equals​(Object object)
        Compares the specified object with this operation for equality.
        Overrides:
        equals in class AbstractOperation
        Parameters:
        object - The object to compare with this operation.
        Returns:
        true if the given object is equals to this operation.
      • hashCode

        public int hashCode()
        Description copied from class: AbstractOperation
        Returns a hash value for this operation. This value need not remain consistent between different implementations of the same class.
        Overrides:
        hashCode in class AbstractOperation
      • handleJAIEXTParams

        protected void handleJAIEXTParams​(ParameterBlockJAI parameters,
                                          ParameterValueGroup parameters2)
        Extension point for adding to the JAI ParameterBlockJAI object the parameters defined in the ParameterValueGroup, which can be read by the JAI-EXT operations.

        Notice that if you are using JAI, the new parameters will not be accepted by the ParameterBlockJAI instance.

        Parameters:
        parameters - ParameterBlockJAI instance used by the current JAI-EXT/JAI operation
        parameters2 - ParameterValueGroup instance containing input operation parameters
      • handleROINoDataProperties

        protected static Map<String,​Object> handleROINoDataProperties​(Map<String,​Object> properties,
                                                                            ParameterBlockJAI parameters,
                                                                            GridCoverage2D sourceCoverage,
                                                                            String operationName,
                                                                            int roiIndex,
                                                                            int noDataIndex,
                                                                            int backgroundIndex)
        This method can be used for creating a property Map to set to the new coverage generated by the current operation. Internally the method will search for ROI and NoData parameters set for the operation and will report them as coverage properties
        Returns:
        A Map containing all the coverage properties and also ROI and NoData if present
      • handleROINoDataInternal

        protected static void handleROINoDataInternal​(ParameterBlockJAI parameters,
                                                      GridCoverage2D sourceCoverage,
                                                      String operationName,
                                                      int roiIndex,
                                                      int noDataIndex)
        This method can be used for merging input coverage properties (ROI and NoData) with the ones provided as input in the ParameterBlock instance. If a ROI instance is already present as a coverage property, it will be intersected with an eventual ROI object defined as a parameter inside the ParameterBlock. If no NoData Range is defined in the parameters but is defined as coverage property, it will be set in the input ParameterBlock