Class Category

  • All Implemented Interfaces:
    Serializable

    public class Category
    extends Object
    implements Serializable
    A category delimited by a range of values. A category may be either qualitative or quantitative. For example, a classified image may have a qualitative category defining sample value 0 as water. An other qualitative category may defines sample value 1 as forest, etc. An other image may define elevation data as sample values in the range [0..100]. The later is a quantitative category, because sample values are related to some measurement in the real world. For example, elevation data may be related to an altitude in metres through the following linear relation:

    altitude = sample value×100.

    Some image mixes both qualitative and quantitative categories. For example, images of Sea Surface Temperature (SST) may have a quantitative category for temperature with values ranging from –2 to 35°C, and three qualitative categories for cloud, land and ice.

    All categories must have a human readable name.

    All Category objects are immutable and thread-safe.

    Since:
    2.1
    Author:
    Martin Desruisseaux (IRD)
    See Also:
    GridSampleDimension, Serialized Form
    • Field Detail

      • NODATA

        public static final Category NODATA
        A default category for "no data" values. This default qualitative category use sample value 0, which is mapped to geophysics value Float.NaN for those who work with floating point images. The rendering color default to a fully transparent color and the name is "no data" localized to the requested locale.
      • FALSE

        public static final Category FALSE
        A default category for the boolean "false" value. This default identity category uses sample value 0, the color black and the name "false" localized to the specified locale.
      • TRUE

        public static final Category TRUE
        A default category for the boolean "true" value. This default identity category uses sample value 1, the color white and the name "true" localized to the specified locale.
    • Constructor Detail

      • Category

        public Category​(CharSequence name,
                        Color color,
                        boolean sample)
        Constructs a qualitative category for a boolean value.
        Parameters:
        name - The category name as a String or InternationalString object.
        color - The category color, or null for a default color.
        sample - The sample value as a boolean.
      • Category

        public Category​(CharSequence name,
                        Color color,
                        int sample)
        Constructs a qualitative category for sample value sample.
        Parameters:
        name - The category name as a String or InternationalString object.
        color - The category color, or null for a default color.
        sample - The sample value as an integer, usually in the range 0 to 255.
      • Category

        public Category​(CharSequence name,
                        Color color,
                        int sample,
                        boolean isQuantitative)
        Constructs a qualitative category for sample value sample.
        Parameters:
        name - The category name as a String or InternationalString object.
        color - The category color, or null for a default color.
        sample - The sample value as an integer, usually in the range 0 to 255.
      • Category

        public Category​(CharSequence name,
                        Color color,
                        double sample)
        Constructs a qualitative category for sample value sample.
        Parameters:
        name - The category name as a String or InternationalString object.
        color - The category color, or null for a default color.
        sample - The sample value as a double. May be one of NaN values.
      • Category

        public Category​(CharSequence name,
                        Color[] colors,
                        int lower,
                        int upper)
                 throws IllegalArgumentException
        Constructs a quantitative category for sample values ranging from lower inclusive to upper exclusive.
        Parameters:
        name - The category name as a String or InternationalString object.
        colors - A set of colors for this category. This array may have any length; colors will be interpolated as needed. An array of length 1 means that an uniform color should be used for all sample values. An array of length 0 or a null array means that some default colors should be used (usually a gradient from opaque black to opaque white).
        lower - The lower sample value, inclusive.
        upper - The upper sample value, exclusive.
        Throws:
        IllegalArgumentException - if lower is not smaller than upper, or if scale or offset are not real numbers.
      • Category

        public Category​(CharSequence name,
                        Color[] colors,
                        NumberRange<? extends Number> sampleValueRange)
                 throws IllegalArgumentException
        Constructs a quantitative category for sample values in the specified range.
        Parameters:
        name - The category name as a String or InternationalString object.
        colors - A set of colors for this category. This array may have any length; colors will be interpolated as needed. An array of length 1 means that an uniform color should be used for all sample values. An array of length 0 or a null array means that some default colors should be used (usually a gradient from opaque black to opaque white).
        sampleValueRange - The range of sample values for this category. Element class is usually Integer, but Float and Double are accepted as well.
        Throws:
        IllegalArgumentException - if lower is not smaller than upper, or if scale or offset are not real numbers.
      • Category

        public Category​(CharSequence name,
                        Color[] colors,
                        NumberRange<? extends Number> sampleValueRange,
                        boolean isQuantitative)
                 throws IllegalArgumentException
        Constructs a qualitative or quantitative category for samples in the specified range.
        Parameters:
        name - The category name as a String or InternationalString object.
        colors - A set of colors for this category. This array may have any length; colors will be interpolated as needed. An array of length 1 means that an uniform color should be used for all sample values. An array of length 0 or a null array means that some default colors should be used (usually a gradient from opaque black to opaque white).
        sampleValueRange - The range of sample values for this category. Element class is usually Integer, but Float and Double are accepted as well.
        Throws:
        ClassCastException - if the range element class is not a Number subclass.
        IllegalArgumentException - if the range is invalid.
    • Method Detail

      • getName

        public InternationalString getName()
        Returns the category name.
        Returns:
        The category name.
      • getColors

        public Color[] getColors()
        Returns the set of colors for this category. Change to the returned array will not affect this category.
        Returns:
        The colors palette for this category.
        See Also:
        GridSampleDimension.getColorModel()
      • isQuantitative

        public boolean isQuantitative()
        Returns true if this category is quantitative.
        Returns:
        true if this category is quantitative, or false if this category is qualitative.
      • recolor

        public Category recolor​(Color[] colors)
        Returns a category for the same range of sample values but a different color palette. The array given in argument may have any length; colors will be interpolated as needed. An array of length 1 means that an uniform color should be used for all sample values. An array of length 0 or a null array means that some default colors should be used (usually a gradient from opaque black to opaque white).
        Parameters:
        colors - A set of colors for the new category.
        Returns:
        A category with the new color palette, or this if the new colors are identical to the current ones.
        See Also:
        org.geotools.coverage.processing.ColorMap#recolor
      • hashCode

        public int hashCode()
        Returns a hash value for this category. This value need not remain consistent between different implementations of the same class.
        Overrides:
        hashCode in class Object
      • equals

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

        public String toString()
        Returns a string representation of this category. The returned string is implementation dependent. It is usually provided for debugging purposes.
        Overrides:
        toString in class Object