Class JGrassColorTable


  • public class JGrassColorTable
    extends Object
    Represents a GRASS rastermap color table.

    Colortables for GRASS 5 and greater are supported.

    Format of the color file, which is located in location/mapset/colr/mapname:

    The first line is a % character and two numbers indicating the minimum and maximum data values which have colors. Note that in JGrass after the range values we add a third value for alpha support.

    After the first line, the list of color rules appears, that can be of the following formats:

    • value1:r:g:b value2:r:g:b interpolation of colors between the two values with the two colors
    • value1:grey value2:grey
    • value1:r:g:b assumption that it means that value1 == value2
    • nv:r:g:b novalues could also have color with such a rule.
    Since:
    3.0
    Author:
    Andrea Antonello (www.hydrologis.com)
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static List<String> createDefaultColorTable​(double[] dataRange, int alpha)
      Creates a default rainbow color table given a data range.
      int getAlpha()
      Getter for the alpha value.
      List<String> getColorRules()
      Getter for the color rules.
      static void parseColorRule​(String rule, double[] values, Color[] colors)
      parses a color rule.
      • Methods inherited from class Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JGrassColorTable

        public JGrassColorTable​(JGrassMapEnvironment readerGrassEnv,
                                double[] dataRange)
                         throws IOException
        Creates a new instance of ColorTable
        Parameters:
        readerGrassEnv - the grass environment used to identify paths.
        dataRange - the datarange to be used if the native one is missing.
        Throws:
        IOException
    • Method Detail

      • createDefaultColorTable

        public static List<String> createDefaultColorTable​(double[] dataRange,
                                                           int alpha)
        Creates a default rainbow color table given a data range.
        Parameters:
        dataRange - the data range for which the color table is created
        Returns:
        the list of color rules as value1:r:g:b value2:r:g:b alpha
      • getColorRules

        public List<String> getColorRules()
        Getter for the color rules.
        Returns:
        the list of color rules.
      • getAlpha

        public int getAlpha()
        Getter for the alpha value.
        Returns:
        the alpha value.
      • parseColorRule

        public static void parseColorRule​(String rule,
                                          double[] values,
                                          Color[] colors)
        parses a color rule.

        Arrays of doubles and colors have to be passed, that will be filled with the values of the color rule.

        Parameters:
        rule - the color rule as taken from the list returned by getColorRules()
        values - the array of doubles to be filled with the values.
        colors - the array of Color to be filled with the colors (can be null).