Package org.geotools.coverage
Class Category
- Object
-
- 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 value0
as water. An other qualitative category may defines sample value1
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
-
-
Constructor Summary
Constructors Constructor Description Category(CharSequence name, Color[] colors, int lower, int upper)
Constructs a quantitative category for sample values ranging fromlower
inclusive toupper
exclusive.Category(CharSequence name, Color[] colors, NumberRange<? extends Number> sampleValueRange)
Constructs a quantitative category for sample values in the specified range.Category(CharSequence name, Color[] colors, NumberRange<? extends Number> sampleValueRange, boolean isQuantitative)
Constructs a qualitative or quantitative category for samples in the specified range.Category(CharSequence name, Color color, boolean sample)
Constructs a qualitative category for a boolean value.Category(CharSequence name, Color color, double sample)
Constructs a qualitative category for sample valuesample
.Category(CharSequence name, Color color, int sample)
Constructs a qualitative category for sample valuesample
.Category(CharSequence name, Color color, int sample, boolean isQuantitative)
Constructs a qualitative category for sample valuesample
.Category(CharSequence name, Color color, NumberRange<?> sampleValueRange)
Constructs a quantitative category for samples in the specified range.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object object)
Compares the specified object with this category for equality.Color[]
getColors()
Returns the set of colors for this category.InternationalString
getName()
Returns the category name.NumberRange<? extends Number>
getRange()
Returns the range of sample values occurring in this category.int
hashCode()
Returns a hash value for this category.boolean
isQuantitative()
Returnstrue
if this category is quantitative.Category
recolor(Color[] colors)
Returns a category for the same range of sample values but a different color palette.String
toString()
Returns a string representation of this category.
-
-
-
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 valueFloat.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
-
TRUE
public static final Category TRUE
-
-
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 aString
orInternationalString
object.color
- The category color, ornull
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 valuesample
.- Parameters:
name
- The category name as aString
orInternationalString
object.color
- The category color, ornull
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 valuesample
.- Parameters:
name
- The category name as aString
orInternationalString
object.color
- The category color, ornull
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 valuesample
.- Parameters:
name
- The category name as aString
orInternationalString
object.color
- The category color, ornull
for a default color.sample
- The sample value as a double. May be one ofNaN
values.
-
Category
public Category(CharSequence name, Color color, NumberRange<?> sampleValueRange) throws IllegalArgumentException
Constructs a quantitative category for samples in the specified range.- Parameters:
name
- The category name as aString
orInternationalString
object.color
- The category color, ornull
for a default color.sampleValueRange
- The range of sample values for this category. Element class is usuallyInteger
, butFloat
andDouble
are accepted as well.- Throws:
IllegalArgumentException
- If the given range is invalid.
-
Category
public Category(CharSequence name, Color[] colors, int lower, int upper) throws IllegalArgumentException
Constructs a quantitative category for sample values ranging fromlower
inclusive toupper
exclusive.- Parameters:
name
- The category name as aString
orInternationalString
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 anull
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
- iflower
is not smaller thanupper
, or ifscale
oroffset
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 aString
orInternationalString
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 anull
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 usuallyInteger
, butFloat
andDouble
are accepted as well.- Throws:
IllegalArgumentException
- iflower
is not smaller thanupper
, or ifscale
oroffset
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 aString
orInternationalString
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 anull
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 usuallyInteger
, butFloat
andDouble
are accepted as well.- Throws:
ClassCastException
- if the range element class is not aNumber
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()
-
getRange
public NumberRange<? extends Number> getRange()
Returns the range of sample values occurring in this category.- Returns:
- The range of sample values.
- See Also:
NumberRange.getMinimum(boolean)
,NumberRange.getMaximum(boolean)
,GridSampleDimension.getMinimumValue()
,GridSampleDimension.getMaximumValue()
-
isQuantitative
public boolean isQuantitative()
Returnstrue
if this category is quantitative.- Returns:
true
if this category is quantitative, orfalse
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 anull
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.
-
equals
public boolean equals(Object object)
Compares the specified object with this category for equality.
-
-