001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2003-2006, GeoTools Project Managment Committee (PMC)
005: * (C) 2002, Centre for Computational Geography
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation;
010: * version 2.1 of the License.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: */
017: package org.geotools.index.rtree;
018:
019: import com.vividsolutions.jts.geom.Envelope;
020: import com.vividsolutions.jts.geom.Geometry;
021: import org.geotools.filter.AbstractFilter;
022: import org.geotools.filter.AttributeExpression;
023: import org.geotools.filter.BetweenFilter;
024: import org.geotools.filter.CompareFilter;
025: import org.geotools.filter.DefaultExpression;
026: import org.geotools.filter.Expression;
027: import org.geotools.filter.FidFilter;
028: import org.geotools.filter.Filter;
029: import org.geotools.filter.FilterVisitor;
030: import org.geotools.filter.Filters;
031: import org.geotools.filter.FunctionExpression;
032: import org.geotools.filter.GeometryFilter;
033: import org.geotools.filter.LikeFilter;
034: import org.geotools.filter.LiteralExpression;
035: import org.geotools.filter.LogicFilter;
036: import org.geotools.filter.MathExpression;
037: import org.geotools.filter.NullFilter;
038:
039: import java.util.Iterator;
040: import java.util.logging.Logger;
041:
042: /**
043: * DOCUMENT ME!
044: *
045: * @author Tommaso Nolli
046: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/shapefile/src/main/java/org/geotools/index/rtree/FilterConsumer.java $
047: */
048: public class FilterConsumer implements FilterVisitor {
049: private static Logger LOGGER = org.geotools.util.logging.Logging
050: .getLogger("org.geotools.index.rtree");
051: private Envelope bounds = null;
052:
053: public Envelope getBounds() {
054: return this .bounds;
055: }
056:
057: /**
058: * @see org.geotools.filter.FilterVisitor#visit(org.geotools.filter.Filter)
059: */
060: public void visit(Filter filter) {
061: if (filter == Filter.NONE) {
062: this .bounds = new Envelope(Double.NEGATIVE_INFINITY,
063: Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY,
064: Double.POSITIVE_INFINITY);
065: } else if (filter == Filter.ALL) {
066: this .bounds = null;
067: } else {
068: LOGGER.warning("Unknown filter type:" + filter.toString());
069: }
070: }
071:
072: /**
073: * @see org.geotools.filter.FilterVisitor#visit(org.geotools.filter.BetweenFilter)
074: */
075: public void visit(BetweenFilter filter) {
076: LOGGER.finest("BetweenFilter ignored!");
077: }
078:
079: /**
080: * @see org.geotools.filter.FilterVisitor#visit(org.geotools.filter.CompareFilter)
081: */
082: public void visit(CompareFilter filter) {
083: LOGGER.finest("CompareFilter ignored!");
084: }
085:
086: /**
087: * @see org.geotools.filter.FilterVisitor#visit(org.geotools.filter.GeometryFilter)
088: */
089: public void visit(GeometryFilter filter) {
090: if (filter.getFilterType() == Filter.GEOMETRY_BBOX
091: || filter.getFilterType() == Filter.GEOMETRY_EQUALS
092: || filter.getFilterType() == Filter.GEOMETRY_INTERSECTS
093: || filter.getFilterType() == Filter.GEOMETRY_TOUCHES
094: || filter.getFilterType() == Filter.GEOMETRY_CROSSES
095: || filter.getFilterType() == Filter.GEOMETRY_WITHIN
096: || filter.getFilterType() == Filter.GEOMETRY_CONTAINS
097: || filter.getFilterType() == Filter.GEOMETRY_OVERLAPS
098: || filter.getFilterType() == Filter.GEOMETRY_DWITHIN) {
099: DefaultExpression left = (DefaultExpression) filter
100: .getLeftGeometry();
101: DefaultExpression right = (DefaultExpression) filter
102: .getRightGeometry();
103:
104: if (left != null) {
105: left.accept(this );
106: }
107:
108: if (right != null) {
109: right.accept(this );
110: }
111: }
112: }
113:
114: /**
115: * @see org.geotools.filter.FilterVisitor#visit(org.geotools.filter.LikeFilter)
116: */
117: public void visit(LikeFilter filter) {
118: LOGGER.finest("LikeFilter ignored!");
119: }
120:
121: /**
122: * @see org.geotools.filter.FilterVisitor#visit(org.geotools.filter.LogicFilter)
123: */
124: public void visit(LogicFilter filter) {
125: switch (filter.getFilterType()) {
126: case AbstractFilter.LOGIC_NOT:
127: LOGGER.finest("[NOT] LogicFilter ignored!");
128:
129: break;
130:
131: case AbstractFilter.LOGIC_OR:
132: LOGGER.finest("[OR] LogicFilter ignored!");
133:
134: break;
135:
136: case AbstractFilter.LOGIC_AND:
137:
138: Iterator list = filter.getFilterIterator();
139:
140: while (list.hasNext()) {
141: Filters.accept((org.opengis.filter.Filter) list.next(),
142: this );
143: }
144:
145: break;
146:
147: default:
148: LOGGER.finest("LogicFilter ignored!");
149: }
150: }
151:
152: /**
153: * @see org.geotools.filter.FilterVisitor#visit(org.geotools.filter.NullFilter)
154: */
155: public void visit(NullFilter filter) {
156: LOGGER.finest("NullFilter ignored!");
157: }
158:
159: /**
160: * @see org.geotools.filter.FilterVisitor#visit(org.geotools.filter.FidFilter)
161: */
162: public void visit(FidFilter filter) {
163: LOGGER.finest("FidFilter ignored!");
164: }
165:
166: /**
167: * @see org.geotools.filter.FilterVisitor#visit(org.geotools.filter.AttributeExpression)
168: */
169: public void visit(AttributeExpression expression) {
170: LOGGER.finest("AttributeExpression ignored!");
171: }
172:
173: /**
174: * @see org.geotools.filter.FilterVisitor#visit(org.geotools.filter.Expression)
175: */
176: public void visit(Expression expression) {
177: LOGGER.finest("Expression ignored!");
178: }
179:
180: /**
181: * @see org.geotools.filter.FilterVisitor#visit(org.geotools.filter.LiteralExpression)
182: */
183: public void visit(LiteralExpression expression) {
184: if (expression.getType() == DefaultExpression.LITERAL_GEOMETRY) {
185: Geometry bbox = (Geometry) expression.getLiteral();
186:
187: if (this .bounds == null) {
188: this .bounds = bbox.getEnvelopeInternal();
189: } else {
190: this .bounds.expandToInclude(bbox.getEnvelopeInternal());
191: }
192: } else {
193: LOGGER.warning("LiteralExpression ignored!");
194: }
195: }
196:
197: /**
198: * @see org.geotools.filter.FilterVisitor#visit(org.geotools.filter.MathExpression)
199: */
200: public void visit(MathExpression expression) {
201: LOGGER.finest("MathExpression ignored!");
202: }
203:
204: /**
205: * @see org.geotools.filter.FilterVisitor#visit(org.geotools.filter.FunctionExpression)
206: */
207: public void visit(FunctionExpression expression) {
208: LOGGER.finest("FunctionExpression ignored!");
209: }
210: }
|