Introduction to OGC filters
For many applications, you need to identify a particular subset of a data set by specifying a number of conditions, so that you can take further action on that subset only. LuciadLightspeed allows you to use OGC filters to identify that data subset.
An OGC Filter is a construct used to constrain the property values of an object type for the purpose of identifying a subset of object instances. It is based on the Filter Encoding standards available on the OGC website. The document describes a system-neutral representation of a query predicate, encoded in XML.
In addition, the specification document defines a set of OGC expressions that can also be used for expressing a computed property of a given object, which is a parametric value that depends on the given object.
A large class of OpenGIS web-based services require the ability to express filters in XML. The Web Feature Service (WFS) uses
the OGC filters in GetFeature
and Transaction
operations to define query constraints. The Styled Layer Descriptor (SLD) specification uses OGC filters to condition the
application of styling rules. It also uses OGC expressions to define variable parameters of styling rules. You can use an
OGC expression to define how the stroke color depends on the object that is being painted, for example.
The OGC filter API in LuciadLightspeed
The LuciadLightspeed OGC filter API provides a Java object representation of OGC filters and expressions independently from the XML encoding. This representation is called the OGC filter model and is described in The OGC filter model. The OGC filter model offers the following advantages:
-
It is independent of any version of the OpenGIS Filter Encoding Implementation specification. It can be obtained by decoding documents conforming to several versions of the specification. The OGC filter model also details how filters can be encoded according several versions of the specification. Moreover, this abstraction layer can help to minimize the impact of the evolution of the specification.
-
It is easier to build and manipulate programmatically than an XML document. It can be used for the creation and the edition of conforming OGC filter XML documents.
-
It is decoupled from any of its possible usages. It can then be evaluated in different ways under different circumstances. But it could also be translated into any other query language like SQL or XQuery in order to be used for querying an external datastore.
For the evaluation of an OGC filter model, the LuciadLightspeed OGC filter API offers a configurable and extensible evaluator that supports most of the constructs of the OGC filter elements.
The OGC filter evaluator allows you to:
-
Build an
ILcdFilter
that can be used for accepting or rejecting a given object. ThisILcdFilter
can then be applied to aTLcdGXYLayer
for example. -
Build an
ILcdPropertyRetriever
than can be used for computing a property of a given object. You can use thisILcdPropertyRetriever
for building SLD symbolizer painters, for example.
See Styling data with OGC SLD for more information.
For a better understanding of the following sections, it is recommended to read the OpenGIS Filter Encoding Implementation specification document first.
The OGC filter model
Overview
An OGC filter is represented by a TLcdOGCFilter
object, which contains a filter condition.
The filter is intended to only accept the objects that meet this condition.
The filter conditions are based on filter expressions and they are built using conditional operators. The OGC filter model has several kinds of conditional operators: comparison operators, logical operators, spatial operators, null check operator, and so on. Each of those conditions is represented by a class listed in Filter conditions.
The filter expressions are the basic constructs of a filter model. They can be either literals, object properties referenced by their name or an XPath expression, functions or the result of arithmetic operations. For those four kinds of filter expression, the OGC filter model contains classes that are described in Filter expressions.
The most commonly used conditions and expressions of the OGC filters can be constructed by using the static methods of the
TLcdOGCFilterFactory
.
Filter expressions
The filter expressions are the basic constructs of the filter conditions. They also allow to express computed properties, or parametric values, that depend on a given object.
Each XML element of the OpenGIS Filter Encoding Implementation specification that represents an expression is modeled by a class in the LuciadLightspeed OGC filter model. This mapping is detailed in Table 1, “LuciadLightspeed classes for OGC filter expression elements”.
The ILcdOGCExpression
interface is the common marker for OGC filter model classes that represent a filter expression.
XML element | Corresponding LuciadLightspeed class |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Examples of filter expressions are shown in Program: Representation of OGC filter expressions.
samples/ogc/filter/model/OGCFilterModelSample
)
/*
<ogc:PropertyName xmlns="http://someserver/myns">lastName</ogc:PropertyName>
*/
TLcdOGCPropertyName propertyName = property("lastName", "http://someserver/myns");
/*
<ogc:PropertyName xmlns="http://someserver/myns">Person/lastName</ogc:PropertyName>
*/
TLcdOGCXPath xpath;
xpath = new TLcdOGCXPath("Person/lastName", "http://someserver/myns");
propertyName = new TLcdOGCPropertyName(xpath);
/*
<ogc:Literal>John Smith</ogc:Literal>
*/
TLcdOGCLiteral literal = literal("John Smith");
/*
<ogc:Literal>6000000</ogc:Literal>
*/
literal = literal(6000000);
/*
<ogc:Function name="SIN" >
<ogc:Literal>3.14159265359</ogc:Literal>
</ogc:Function>
*/
TLcdOGCFunction function = function("SIN", literal(Math.PI));
/*
<ogc:Add>
<ogc:PropertyName xmlns="http://someserver/myns">lane</ogc:PropertyName>
<ogc:Literal>-1</ogc:Literal>
</ogc:Add>
*/
TLcdOGCBinaryOperator binaryOperator = add(property("lane", "http://someserver/myns"),
literal(-1));
Filter conditions
The filter conditions are the filter constructs that return either true or false for a given object. They are used in TLcdOGCFilter
for defining which object must be accepted or rejected.
Each XML element of the OpenGIS Filter Encoding Implementation specification that represents a condition is modeled by a class in the LuciadLightspeed OGC filter model. This mapping is detailed in Table 2, “LuciadLightspeed classes for OGC filter condition elements”.
The ILcdOGCCondition
interface is the common marker for OGC filter model classes that represent a filter condition.
XML element | Corresponding LuciadLightspeed class |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Examples of filter conditions are shown in Program: Representation of OGC filter comparison conditions, Program: Representation of OGC filter spatial conditions and Program: Representation of OGC filter logic conditions.
samples/ogc/filter/model/OGCFilterModelSample
)
/*
<ogc:PropertyIsGreaterThan>
<ogc:PropertyName xmlns="http://someserver/myns">elevation</ogc:PropertyName>
<ogc:Literal>0</ogc:Literal>
</ogc:PropertyIsGreaterThan>
*/
TLcdOGCBinaryComparisonOperator binaryComparisonOperator =
gt(property("elevation", "http://someserver/myns"), literal(0));
/*
<ogc:PropertyIsLike wildCard="*" singleChar="?" escapeChar="\">
<ogc:PropertyName xmlns="http://someserver/myns">lastName</ogc:PropertyName>
<ogc:Literal>John*</ogc:Literal>
</ogc:PropertyIsLike>
*/
TLcdOGCIsLikeOperator isLikeOperator =
like(property("lastName", "http://someserver/myns"), "John*");
samples/ogc/filter/model/OGCFilterModelSample
)
/*
<ogc:BBOX>
<ogc:PropertyName>Geometry</ogc:PropertyName>
<gml:Envelope srsName="EPSG:4326">
<gml:lowerCorner>13.0983 31.5899</gml:lowerCorner>
<gml:upperCorner>35.5472 42.8143</gml:upperCorner>
</gml:Envelope>
</ogc:BBOX>
*/
TLcdOGCBBoxOperator bboxOperator = new TLcdOGCBBoxOperator(
property("Geometry", "http://www.opengis.net/ogc"),
new TLcdLonLatBounds(13.0983, 31.5899, (35.5472 - 13.0983), (42.8143 - 31.5899)),
new TLcdGeodeticReference(new TLcdGeodeticDatum()));
/*
<ogc:Intersects>
<ogc:PropertyName>Geometry</ogc:PropertyName>
<gml:Envelope srsName="EPSG:4326">
<gml:lowerCorner>13.0983 31.5899</gml:lowerCorner>
<gml:upperCorner>35.5472 42.8143</gml:upperCorner>
</gml:Envelope>
</ogc:Intersects>
*/
TLcdOGCBinarySpatialOperator binarySpatialOperator = new TLcdOGCBinarySpatialOperator(
TLcdOGCBinarySpatialOperator.INTERSECTS,
property("Geometry", "http://www.opengis.net/ogc"),
new TLcdLonLatBounds(13.0983, 31.5899, (35.5472 - 13.0983), (42.8143 - 31.5899)),
new TLcdGeodeticReference(new TLcdGeodeticDatum()));
samples/ogc/filter/model/OGCFilterModelSample
)
/*
<ogc:And>
<ogc:Not>
<ogc:PropertyIsNull>
<ogc:PropertyName xmlns="http://someserver/myns">elevation</ogc:PropertyName>
</ogc:PropertyIsNull>
</ogc:Not>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName xmlns="http://someserver/myns">elevation</ogc:PropertyName>
<ogc:Literal>0</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:And>
*/
TLcdOGCBinaryLogicOperator binaryLogicOperator =
and(not(isNull(property("elevation", "http://someserver/myns"))),
eq(property("elevation", "http://someserver/myns"), literal(0)));
Limitations
The TLcdOGCFilterEvaluator
supports spatial operators with the following limitations:
-
If the Advanced GIS Engine component is not available in your LuciadLightspeed installation, only the
BBOX
operator is supported. -
With the exception of the
BBOX
operator, the spatial evaluators do not perform georeference transformations. As a consequence, they cannot compare geometries with two distinct georeferences. -
The
Crosses
andOverlaps
operators only work for 2D curves.