Skip to end of metadata
Go to start of metadata

An Expression is an object that can perform some kind of calculation on a Feature and provide a result (that is, a generic Object, meaning that the result can really be anything). As you can see, the Expression is quite a generic concept, and the Geotools library provides some default implementations that are useful in data access and map styling which can be seen in the following class diagram.

As you can see from the class diagram, they are just interfaces. Since you need to create actual objects, you will use the FilterFactory that can create objects implementing those interfaces.

Expressions are usually composed of other expressions, until a simpler one, the LiteralExpression or an AttributeExpression, is used. The LiteralExpression is a literal, that is, it does not depend on the feature contents and is a constant value. On the other hand, an AttributeExpression will extract the value of a particular Feature attribute. Every other Expression will build on top of these expressions.
For example, a MathExpression of type "sum" will sum two other expressions, which may be literals, attributes, or composite expressions. For those of you familiar with compiler internals, a complex mathematical expression will be represented in Geotools2 as its evaluation tree where each node is an Expression object.

How to build an expression?

There are many ways to create an expression :

  • with java code
  • within xml file
  • by using an expression builder


Here is a simple example that extends the code of the basic feature tutorial by creating a simple sum expression that will sum the constant 2 and the contents of the attribute "width" of the passed feature.


expression builder

A Simple Math Expression (from Snippets)

Simple math expression which processes a simple add on two integers.

  • No labels