org.geotools.demo.filter.function
Class ColorRampFunction

java.lang.Object
  extended by org.geotools.demo.filter.function.ColorRampFunction
All Implemented Interfaces:
org.opengis.filter.expression.Expression, org.opengis.filter.expression.Function

public class ColorRampFunction
extends java.lang.Object
implements org.opengis.filter.expression.Function

Illustrates how to write a custom filter function that implements the Function interface directly. The example here is a function that can be used in a Style to dynamically set the fill color of polygon features based on a numeric feature attribute (e.g. country population size).

GeoTools provides a great many useful filter functions for numeric and spatial operations but sometimes it is still necessary, or perhaps easier, for users to create custom functions. This can be done by extending the GeoTools classes or, as in this example, implementing the Function interface directly.

Author:
Michael Bedward

Field Summary
 
Fields inherited from interface org.opengis.filter.expression.Expression
NIL
 
Constructor Summary
ColorRampFunction(org.opengis.filter.expression.Expression valueExpr, float minValue, float maxValue, float saturation, float brightness)
          Constructor.
 
Method Summary
 java.lang.Object accept(org.opengis.filter.expression.ExpressionVisitor visitor, java.lang.Object arg)
          Accept a visitor that wishes to examine this function's parameters.
 java.lang.Object evaluate(java.lang.Object feature)
          Evaluate the function for a given feature.
<T> T
evaluate(java.lang.Object feature, java.lang.Class<T> clazz)
          Evaluate the function for a given feature.
 org.opengis.filter.expression.Literal getFallbackValue()
          Get the fallback value for this function
 java.lang.String getName()
          Get the name of this function
 java.util.List<org.opengis.filter.expression.Expression> getParameters()
          Get the parameters that have been set for this function (only one parameter for the current implementation).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ColorRampFunction

public ColorRampFunction(org.opengis.filter.expression.Expression valueExpr,
                         float minValue,
                         float maxValue,
                         float saturation,
                         float brightness)
Constructor.

Parameters:
valueExpr - the expression that will be used to get the feature value from which the fill color will be calculated
minValue - minimum expected feature value
maxValue - maximum expected feature value
saturation - HSB color model saturation (between 0 and 1)
brightness - HSB color model brightness (between 0 and 1)
Method Detail

getName

public java.lang.String getName()
Get the name of this function

Specified by:
getName in interface org.opengis.filter.expression.Function
Returns:
function name

getParameters

public java.util.List<org.opengis.filter.expression.Expression> getParameters()
Get the parameters that have been set for this function (only one parameter for the current implementation).

Specified by:
getParameters in interface org.opengis.filter.expression.Function
Returns:
live list of function parameters

getFallbackValue

public org.opengis.filter.expression.Literal getFallbackValue()
Get the fallback value for this function

Specified by:
getFallbackValue in interface org.opengis.filter.expression.Function
Returns:
Color.GRAY as a Literal object

evaluate

public java.lang.Object evaluate(java.lang.Object feature)
Evaluate the function for a given feature. The feature's value will be extracted and a color calculated to use as the polygon fill.

Specified by:
evaluate in interface org.opengis.filter.expression.Expression
Parameters:
feature - the input feature
Returns:
a Color object

evaluate

public <T> T evaluate(java.lang.Object feature,
                      java.lang.Class<T> clazz)
Evaluate the function for a given feature. The feature's value will be extracted and a color calculated to use as the polygon fill.

Specified by:
evaluate in interface org.opengis.filter.expression.Expression
Type Parameters:
T - type parameter - must be Color or a subclass
Parameters:
feature - the input feature
clazz - a Class object for the type (e.g. Color.class)
Returns:
a Color object

accept

public java.lang.Object accept(org.opengis.filter.expression.ExpressionVisitor visitor,
                               java.lang.Object arg)
Accept a visitor that wishes to examine this function's parameters. This method will be invoked during the rendering process to get Stroke and Fill attributes.

Specified by:
accept in interface org.opengis.filter.expression.Expression
Parameters:
visitor - a visitor object
arg - visitor-specific argument
Returns:
result of the visit


Copyright © 1996-2010 Geotools. All Rights Reserved.