org.geotools.filter.spatial
Class AbstractPreparedGeometryFilter

java.lang.Object
  extended by org.geotools.filter.FilterAbstract
      extended by org.geotools.filter.AbstractFilter
          extended by org.geotools.filter.BinaryComparisonAbstract
              extended by org.geotools.filter.GeometryFilterImpl
                  extended by org.geotools.filter.spatial.AbstractPreparedGeometryFilter
All Implemented Interfaces:
FilterType, GeometryFilter, org.opengis.filter.BinaryComparisonOperator, org.opengis.filter.Filter, org.opengis.filter.spatial.BinarySpatialOperator, org.opengis.filter.spatial.SpatialOperator
Direct Known Subclasses:
BBOXImpl, ContainsImpl, DisjointImpl, IntersectsImpl, WithinImpl

public abstract class AbstractPreparedGeometryFilter
extends GeometryFilterImpl

A base class for GeometryFilters that will use PreparedGeometries when the Expression is a Literal Expression.

This class determines when the expressions are set which expressions are literals. The protected field literals contains the AbstractPreparedGeometryFilter.Literals enumerated value that indicates if:

If BOTH of the expressions are literals then a cached value is generated by calling {@link #basicEvaluate(Geometry, Geometry)}.

The method {@link #basicEvaluate(Geometry, Geometry)} is required to be implemented so that a cached value can be generated in the case that both expressions are literals



Example usage for intersects filter:

    public boolean evaluate(Object feature) {
        if (feature instanceof SimpleFeature
                && !validate((SimpleFeature) feature)) {
            // we could not obtain a geometry for both left and right hand sides
            // so default to false
            return false;
        }
        Geometry left;
        Geometry right;

        switch (literals) {
        case BOTH:
            return cacheValue;
        case RIGHT: {
            return rightPreppedGeom.intersects(getLeftGeometry(feature));
        }
        case LEFT: {
            return leftPreppedGeom.intersects(getRightGeometry(feature));
        }
        default: {
            left = getLeftGeometry(feature);
            right = getRightGeometry(feature);
            return basicEvaluate(left, right);
        }
        }
    }

    protected final boolean basicEvaluate(Geometry left, Geometry right) {
        Envelope envLeft = left.getEnvelopeInternal();
        Envelope envRight = right.getEnvelopeInternal();
        return envRight.intersects(envLeft) && left.intersects(right);
    }
    

Author:
jesse

Nested Class Summary
protected static class AbstractPreparedGeometryFilter.Literals
          Constant that identifies which expressions are Literal and JTS Geometries
 
Field Summary
protected  boolean cacheValue
          If both expressions are literals the value will never change.
protected  com.vividsolutions.jts.geom.prep.PreparedGeometry leftPreppedGeom
          The PreparedGeometry for the left Geometry.
protected  AbstractPreparedGeometryFilter.Literals literals
          Indicates which expressions are Literals
protected  com.vividsolutions.jts.geom.prep.PreparedGeometry rightPreppedGeom
          The PreparedGeometry for the right Geometry.
 
Fields inherited from class org.geotools.filter.BinaryComparisonAbstract
expression1, expression2
 
Fields inherited from class org.geotools.filter.AbstractFilter
filterType, permissiveConstruction
 
Fields inherited from class org.geotools.filter.FilterAbstract
factory
 
Fields inherited from interface org.geotools.filter.Filter
ALL, NONE
 
Fields inherited from interface org.geotools.filter.FilterType
BETWEEN, COMPARE_EQUALS, COMPARE_GREATER_THAN, COMPARE_GREATER_THAN_EQUAL, COMPARE_LESS_THAN, COMPARE_LESS_THAN_EQUAL, COMPARE_NOT_EQUALS, FID, GEOMETRY_BBOX, GEOMETRY_BEYOND, GEOMETRY_CONTAINS, GEOMETRY_CROSSES, GEOMETRY_DISJOINT, GEOMETRY_DWITHIN, GEOMETRY_EQUALS, GEOMETRY_INTERSECTS, GEOMETRY_OVERLAPS, GEOMETRY_TOUCHES, GEOMETRY_WITHIN, LIKE, LOGIC_AND, LOGIC_NOT, LOGIC_OR, NULL
 
Fields inherited from interface org.opengis.filter.Filter
EXCLUDE, INCLUDE
 
Constructor Summary
protected AbstractPreparedGeometryFilter(org.opengis.filter.FilterFactory factory, org.opengis.filter.expression.Expression e1, org.opengis.filter.expression.Expression e2)
           
 
Method Summary
protected abstract  boolean basicEvaluate(com.vividsolutions.jts.geom.Geometry left, com.vividsolutions.jts.geom.Geometry right)
          Performs the calculation on the two geometries.
 void setExpression1(org.opengis.filter.expression.Expression expression)
           
 void setExpression2(org.opengis.filter.expression.Expression expression)
           
 
Methods inherited from class org.geotools.filter.GeometryFilterImpl
addLeftGeometry, addRightGeometry, equals, evaluate, getLeftGeometry, getLeftGeometry, getRightGeometry, getRightGeometry, hashCode, toString, validate
 
Methods inherited from class org.geotools.filter.BinaryComparisonAbstract
and, comparable, eval, getExpression1, getExpression2, isMatchingCase, not, or
 
Methods inherited from class org.geotools.filter.AbstractFilter
accept, contains, getFilterType, isCompareFilter, isGeometryDistanceFilter, isGeometryFilter, isLogicFilter, isMathFilter, isSimpleFilter
 
Methods inherited from class org.geotools.filter.FilterAbstract
accept, accepts, eval, eval, eval
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.geotools.filter.GeometryFilter
contains
 
Methods inherited from interface org.geotools.filter.Filter
accept, and, getFilterType, not, or
 
Methods inherited from interface org.opengis.filter.spatial.BinarySpatialOperator
getExpression1, getExpression2
 
Methods inherited from interface org.opengis.filter.Filter
accept, evaluate
 

Field Detail

literals

protected AbstractPreparedGeometryFilter.Literals literals
Indicates which expressions are Literals


leftPreppedGeom

protected com.vividsolutions.jts.geom.prep.PreparedGeometry leftPreppedGeom
The PreparedGeometry for the left Geometry. Null if the left geometry is not a Literal


rightPreppedGeom

protected com.vividsolutions.jts.geom.prep.PreparedGeometry rightPreppedGeom
The PreparedGeometry for the right Geometry. Null if the right geometry is not a Literal


cacheValue

protected boolean cacheValue
If both expressions are literals the value will never change. In that case this field is that calculated value. It is false otherwise.

Constructor Detail

AbstractPreparedGeometryFilter

protected AbstractPreparedGeometryFilter(org.opengis.filter.FilterFactory factory,
                                         org.opengis.filter.expression.Expression e1,
                                         org.opengis.filter.expression.Expression e2)
Method Detail

setExpression1

public void setExpression1(org.opengis.filter.expression.Expression expression)
Overrides:
setExpression1 in class GeometryFilterImpl

setExpression2

public void setExpression2(org.opengis.filter.expression.Expression expression)
Overrides:
setExpression2 in class GeometryFilterImpl

basicEvaluate

protected abstract boolean basicEvaluate(com.vividsolutions.jts.geom.Geometry left,
                                         com.vividsolutions.jts.geom.Geometry right)
Performs the calculation on the two geometries. This is used to calculate the cached value in the case that both geometries are Literals. But in practice it is useful to extract this functionality into its own method.

Parameters:
left - the geometry on the left of the equations (the geometry obtained from evaluating Expression1)
right - the geometry on the right of the equations (the geometry obtained from evaluating Expression2)
Returns:
true if the filter evaluates to true for the two geometries


Copyright © 1996-2010 Geotools. All Rights Reserved.