Package org.geotools.filter.spatial
Class AbstractPreparedGeometryFilter
Object
FilterAbstract
AbstractFilter
BinaryComparisonAbstract
GeometryFilterImpl
AbstractPreparedGeometryFilter
- All Implemented Interfaces:
Filter,MultiValuedFilter,BinarySpatialOperator,SpatialOperator,FilterType
- Direct Known Subclasses:
BBOXImpl,ContainsImpl,DisjointImpl,IntersectsImpl,WithinImpl
A base class for GeometryFilters that will use PreparedGeometries when the Expression
is a Literal Expression.
Example usage for intersects filter:
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:
- NEITHER ({@link Literals#NEITHER) of the expressions are literal and is a JTS Geometry (also non-null)
- BOTH (
AbstractPreparedGeometryFilter.Literals.BOTH) expressions are literals and is a JTS Geometry (also non-null) - the LEFT (
AbstractPreparedGeometryFilter.Literals.LEFT) expression (Expression1) is a literal and is a JTS Geometry (also non-null) - or the RIGHT (
AbstractPreparedGeometryFilter.Literals.RIGHT) expression (Expression2) is a literal and is a JTS Geometry (also non-null)
If BOTH of the expressions are literals then a cached value is generated by calling basicEvaluate(Geometry, Geometry).
The method 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
Nested ClassesModifier and TypeClassDescriptionprotected static enumConstant that identifies which expressions are Literal and JTS GeometriesNested classes/interfaces inherited from interface MultiValuedFilter
MultiValuedFilter.MatchAction -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanIf both expressions are literals the value will never change.protected PreparedGeometryThe PreparedGeometry for the left Geometry.protected AbstractPreparedGeometryFilter.LiteralsIndicates which expressions areLiteralsprotected PreparedGeometryThe PreparedGeometry for the right Geometry.Fields inherited from class GeometryFilterImpl
matchActionFields inherited from class BinaryComparisonAbstract
expression1, expression2Fields inherited from class AbstractFilter
LOGGERFields inherited from interface FilterType
ALL, 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, NONE, NULL -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedprotectedAbstractPreparedGeometryFilter(Expression e1, Expression e2, MultiValuedFilter.MatchAction matchAction) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract booleanbasicEvaluate(Geometry left, Geometry right) Performs the calculation on the two geometries.voidsetExpression1(Expression expression) voidsetExpression2(Expression expression) Methods inherited from class GeometryFilterImpl
equals, evaluate, evaluateInternal, getGeometries, getMatchAction, hashCode, toStringMethods inherited from class BinaryComparisonAbstract
comparable, eval, eval, getExpression1, getExpression2, isMatchingCaseMethods inherited from class AbstractFilter
isCompareFilter, isGeometryDistanceFilter, isGeometryFilter, isLogicFilter, isMathFilter, isSimpleFilterMethods inherited from class FilterAbstract
accepts, eval, evalMethods inherited from interface BinarySpatialOperator
getExpression1, getExpression2
-
Field Details
-
literals
Indicates which expressions areLiterals -
leftPreppedGeom
The PreparedGeometry for the left Geometry. Null if the left geometry is not aLiteral -
rightPreppedGeom
The PreparedGeometry for the right Geometry. Null if the right geometry is not aLiteral -
cacheValue
protected boolean cacheValueIf both expressions are literals the value will never change. In that case this field is that calculated value. It is false otherwise.
-
-
Constructor Details
-
AbstractPreparedGeometryFilter
-
AbstractPreparedGeometryFilter
protected AbstractPreparedGeometryFilter(Expression e1, Expression e2, MultiValuedFilter.MatchAction matchAction)
-
-
Method Details
-
setExpression1
- Overrides:
setExpression1in classBinaryComparisonAbstract
-
setExpression2
- Overrides:
setExpression2in classBinaryComparisonAbstract
-
basicEvaluate
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
-