org.geotools.filter
Class GeometryFilterImpl

java.lang.Object
  extended byorg.geotools.filter.AbstractFilter
      extended byorg.geotools.filter.AbstractFilterImpl
          extended byorg.geotools.filter.GeometryFilterImpl
All Implemented Interfaces:
Filter, FilterType, GeometryFilter
Direct Known Subclasses:
CartesianDistanceFilter

public class GeometryFilterImpl
extends AbstractFilterImpl
implements GeometryFilter

Implements a geometry filter.

This filter implements a relationship - of some sort - between two geometry expressions. Note that this comparison does not attempt to restict its expressions to be meaningful. This means that it considers itself a valid filter as long as it contains two geometry sub-expressions. It is also slightly less restrictive than the OGC Filter specification because it does not require that one sub-expression be an geometry attribute and the other be a geometry literal.

In other words, you may use this filter to compare two geometries in the same feature, such as: attributeA inside attributeB? You may also compare two literal geometries, although this is fairly meaningless, since it could be reduced (ie. it is always either true or false). This approach is very similar to that taken in the FilterCompare class.

Version:
$Id: GeometryFilterImpl.java,v 1.15 2004/04/12 16:53:20 aaime Exp $
Author:
Rob Hranac, TOPP
Task:
REVISIT: make this class (and all filters) immutable, implement cloneable and return new filters when calling addLeftGeometry and addRightG Issues to think through: would be cleaner immutability to have constructor called with left and right Geometries, but this does not jive with SAX parsing, which is one of the biggest uses of filters. But the alternative is not incredibly efficient either, as there will be two filters that are just thrown away every time we make a full geometry filter. These issues extend to most filters, as just about all of them are mutable when creating them. Other issue is that lots of code will need to be changed for immutability. (comments by cholmes) - MUTABLE FACTORIES! Sax and immutability.

Field Summary
protected  Expression leftGeometry
          Holds the 'left' value of this comparison filter.
protected  Expression rightGeometry
          Holds the 'right' value of this comparison filter.
 
Fields inherited from class org.geotools.filter.AbstractFilter
filterType, permissiveConstruction
 
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
 
Constructor Summary
protected GeometryFilterImpl(short filterType)
          Constructor with filter type.
 
Method Summary
 void accept(FilterVisitor visitor)
          Used by FilterVisitors to perform some action on this filter instance.
 void addLeftGeometry(Expression leftGeometry)
          Adds the 'left' value to this filter.
 void addRightGeometry(Expression rightGeometry)
          Adds the 'right' value to this filter.
 boolean contains(Feature feature)
          Determines whether or not a given feature is 'inside' this filter.
 boolean equals(java.lang.Object obj)
          Compares this filter to the specified object.
 Expression getLeftGeometry()
          Retrieves the expression on the left side of the comparison.
 Expression getRightGeometry()
          Retrieves the expression on the right side of the comparison.
 int hashCode()
          Override of hashCode method.
 java.lang.String toString()
          Return this filter as a string.
 
Methods inherited from class org.geotools.filter.AbstractFilterImpl
and, not, or
 
Methods inherited from class org.geotools.filter.AbstractFilter
getFilterType, isCompareFilter, isGeometryDistanceFilter, isGeometryFilter, isLogicFilter, isMathFilter, isSimpleFilter
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.geotools.filter.Filter
and, getFilterType, not, or
 

Field Detail

leftGeometry

protected Expression leftGeometry
Holds the 'left' value of this comparison filter.


rightGeometry

protected Expression rightGeometry
Holds the 'right' value of this comparison filter.

Constructor Detail

GeometryFilterImpl

protected GeometryFilterImpl(short filterType)
                      throws IllegalFilterException
Constructor with filter type.

Parameters:
filterType - The type of comparison.
Throws:
IllegalFilterException - Non-geometry type.
Method Detail

addLeftGeometry

public void addLeftGeometry(Expression leftGeometry)
                     throws IllegalFilterException
Adds the 'left' value to this filter.

Specified by:
addLeftGeometry in interface GeometryFilter
Parameters:
leftGeometry - Expression for 'left' value.
Throws:
IllegalFilterException - Filter is not internally consistent.
Task:
REVISIT: make all filters immutable.

addRightGeometry

public void addRightGeometry(Expression rightGeometry)
                      throws IllegalFilterException
Adds the 'right' value to this filter.

Specified by:
addRightGeometry in interface GeometryFilter
Parameters:
rightGeometry - Expression for 'right' value.
Throws:
IllegalFilterException - Filter is not internally consistent.
Task:
REVISIT: make immutable.

getLeftGeometry

public Expression getLeftGeometry()
Retrieves the expression on the left side of the comparison.

Specified by:
getLeftGeometry in interface GeometryFilter
Returns:
the expression on the left.

getRightGeometry

public Expression getRightGeometry()
Retrieves the expression on the right side of the comparison.

Specified by:
getRightGeometry in interface GeometryFilter
Returns:
the expression on the right.

contains

public boolean contains(Feature feature)
Determines whether or not a given feature is 'inside' this filter.

Specified by:
contains in interface GeometryFilter
Specified by:
contains in class AbstractFilter
Parameters:
feature - Specified feature to examine.
Returns:
Flag confirming whether or not this feature is inside filter.

toString

public java.lang.String toString()
Return this filter as a string.

Returns:
String representation of this geometry filter.

equals

public boolean equals(java.lang.Object obj)
Compares this filter to the specified object. Returns true if the passed in object is the same as this filter. Checks to make sure the filter types are the same as well as the left and right geometries.

Parameters:
obj - - the object to compare this GeometryFilter against.
Returns:
true if specified object is equal to this filter; else false

hashCode

public int hashCode()
Override of hashCode method.

Returns:
a hash code value for this geometry filter.

accept

public void accept(FilterVisitor visitor)
Used by FilterVisitors to perform some action on this filter instance. Typicaly used by Filter decoders, but may also be used by any thing which needs infomration from filter structure. Implementations should always call: visitor.visit(this); It is importatant that this is not left to a parent class unless the parents API is identical.

Specified by:
accept in interface Filter
Specified by:
accept in class AbstractFilter
Parameters:
visitor - The visitor which requires access to this filter, the method must call visitor.visit(this);


Copyright © GeoTools. All Rights Reserved.