Class BandArithmetic


  • public class BandArithmetic
    extends Object
    Provides band arithmetic utility methods.
    • Method Detail

      • registerSymbol

        public static void registerSymbol​(Symbol s)
        Registers a new global symbol.
        Parameters:
        s - the symbol
      • deregisterSymbol

        public static void deregisterSymbol​(Symbol s)
        De-registers an existing global symbol.
        Parameters:
        s - the symbol
      • registerFunction

        public static void registerFunction​(Function f)
        Registers a new global function.
        Parameters:
        f - the function
      • deregisterFunction

        public static void deregisterFunction​(Function f)
        De-registers an existing global function.
        Parameters:
        f - the function
      • parseExpression

        public static Term parseExpression​(String expression,
                                           Product contextProduct)
                                    throws ParseException
        Parses the given expression.
        Parameters:
        expression - the expression
        contextProduct - the context product
        Returns:
        the compiled expression
        Throws:
        ParseException - if a parse error occurs
      • parseExpression

        public static Term parseExpression​(String expression,
                                           Product[] products,
                                           int contextProductIndex)
                                    throws ParseException
        Parses the given expression.
        Parameters:
        expression - the expression
        products - the array of source products which form the valid namespace for the expression
        contextProductIndex - the index of the context product for which also symbols without the product prefix $ref-no are registered in the namespace
        Returns:
        the compiled expression
        Throws:
        ParseException - if a parse error occurs
      • createDefaultNamespace

        public static WritableNamespace createDefaultNamespace​(Product[] products,
                                                               int contextProductIndex)
        Creates a default namespace for the product(s) given in an array. The resulting namespace contains symbols for all tie-point grids, bands and single flag values. if the array contains more then one product, the symbol's name will have a prefix according to each product's reference number.
        Parameters:
        products - the array of source products which form the valid namespace for the expression
        contextProductIndex - the index of the context product for which also symbols without the product prefix $ref-no are registered in the namespace
        Returns:
        a default namespace, never null
      • createDefaultNamespace

        public static WritableNamespace createDefaultNamespace​(Product[] products,
                                                               int contextProductIndex,
                                                               ProductNamespacePrefixProvider... prefixProviders)
        Creates a default namespace for the product(s) given in an array. The resulting namespace contains symbols for all tie-point grids, bands and single flag values. if the array contains more then one product, the symbol's name will have a prefix according to each product's reference number.
        Parameters:
        products - the array of source products which form the valid namespace for the expression
        contextProductIndex - the index of the context product for which also symbols without the product prefix $ref-no are registered in the namespace
        prefixProviders - a list of product prefix providers
        Returns:
        a default namespace, never null
      • getRefRasters

        public static RasterDataNode[] getRefRasters​(String expression,
                                                     Product... products)
                                              throws ParseException
        Utility method which returns all raster data nodes referenced in the given band math expressions.
        Parameters:
        expression - the expression
        products - the array of source products which form the valid namespace for the expression
        Returns:
        the array of raster data nodes, which may be empty
        Throws:
        ParseException
      • getRefRasters

        public static RasterDataNode[] getRefRasters​(String expression,
                                                     Product[] products,
                                                     int contextProductIndex)
                                              throws ParseException
        Utility method which returns all raster data nodes referenced in the given band math expressions.
        Parameters:
        expression - the expression
        products - the array of source products which form the valid namespace for the expression
        contextProductIndex - the index of the context product for which also symbols without the product prefix $ref-no are registered in the namespace
        Returns:
        the array of raster data nodes, which may be empty
        Throws:
        ParseException
      • getRefRasters

        public static RasterDataNode[] getRefRasters​(Term... terms)
        Utility method which returns all raster data nodes referenced in the given compiled band math expressions.
        Parameters:
        terms - the array of terms to be analysed
        Returns:
        the array of raster data nodes, which may be empty
      • getRefRasterDataSymbols

        public static RasterDataSymbol[] getRefRasterDataSymbols​(Term... terms)
        Utility method which returns all raster data symbols referenced in a given compiled band math expressions. The order of the returned rasters is the order they appear in the given terms.
        Parameters:
        terms - the compiled band math expressions
        Returns:
        the array of raster data symbols, never null but may be empty
      • createExternalName

        public static String createExternalName​(String name)
        Create an external name from the given name. If the given name contains character which are not valid in an external name the name is escaped with single quotes.

        The method simply delgates to Tokenizer.createExternalName(String).

        Parameters:
        name - the name
        Returns:
        a valid external name
      • getProductNodeNamePrefix

        public static String getProductNodeNamePrefix​(Product product)
        Gets a symbol name prefix for the names of bands, tie point grids, flags, etc. of the given product. The prefix is of the general form "$refNo." where refNo is the product's reference number returned by Product.getRefNo().
        Parameters:
        product - the product, must not be null
        Returns:
        a node name prefix, never null.
      • areRastersEqualInSize

        public static boolean areRastersEqualInSize​(Term term)
        Determines whether all rasters which are referenced in a term are compatible.
        Parameters:
        term - The term in question
        Returns:
        true if the rasters are compatible
      • areRastersEqualInSize

        public static boolean areRastersEqualInSize​(Product product,
                                                    String... expressions)
                                             throws ParseException
        Determines whether all rasters which are referenced in the given expressions are compatible.
        Parameters:
        product - The product to which the expressions can refer
        expressions - the expressions in question
        Returns:
        true if all referenced rasters are compatible
        Throws:
        ParseException - if a parse error occurs
      • areRastersEqualInSize

        public static boolean areRastersEqualInSize​(Product[] products,
                                                    int defaultProductIndex,
                                                    String... expressions)
                                             throws ParseException
        Determines whether all rasters which are referenced in the given expressions are compatible.
        Parameters:
        products - The product to which the expressions can refer
        defaultProductIndex - The index of the default product
        expressions - the expressions in question
        Returns:
        true if all referenced rasters are compatible
        Throws:
        ParseException - if a parse error occurs