001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2006, GeoTools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.filter.spatial;
017:
018: import org.geotools.feature.Feature;
019: import org.geotools.filter.AttributeExpressionImpl;
020: import org.geotools.filter.AttributeExpressionImpl2;
021: import org.geotools.filter.FilterFactory;
022: import org.geotools.filter.GeometryFilterImpl;
023: import org.opengis.filter.FilterVisitor;
024: import org.opengis.filter.expression.Expression;
025: import org.opengis.filter.expression.PropertyName;
026: import org.opengis.filter.spatial.BBOX;
027:
028: import com.vividsolutions.jts.geom.Envelope;
029: import com.vividsolutions.jts.geom.Geometry;
030:
031: public class BBOXImpl extends GeometryFilterImpl implements BBOX {
032:
033: double minx, miny, maxx, maxy;
034: String srs;
035:
036: public BBOXImpl(FilterFactory factory, Expression e1, Expression e2) {
037: super (factory, e1, e2);
038:
039: //backwards compat with old type system
040: this .filterType = GEOMETRY_BBOX;
041: }
042:
043: public String getPropertyName() {
044: PropertyName propertyName = (PropertyName) getExpression1();
045: return propertyName.getPropertyName();
046: }
047:
048: public void setPropertyName(String propertyName) {
049: setExpression1(new AttributeExpressionImpl(propertyName));
050: }
051:
052: public String getSRS() {
053: return srs;
054: }
055:
056: public void setSRS(String srs) {
057: this .srs = srs;
058: }
059:
060: public double getMinX() {
061: return minx;
062: }
063:
064: public void setMinX(double minx) {
065: this .minx = minx;
066: }
067:
068: public double getMinY() {
069: return miny;
070: }
071:
072: public void setMinY(double miny) {
073: this .miny = miny;
074: }
075:
076: public double getMaxX() {
077: return maxx;
078: }
079:
080: public void setMaxX(double maxx) {
081: this .maxx = maxx;
082: }
083:
084: public double getMaxY() {
085: return maxy;
086: }
087:
088: public void setMaxY(double maxy) {
089: this .maxy = maxy;
090: }
091:
092: public boolean evaluate(Object feature) {
093: if (feature instanceof Feature && !validate((Feature) feature))
094: return false;
095:
096: Geometry left = getLeftGeometry(feature);
097: Geometry right = getRightGeometry(feature);
098:
099: Envelope envLeft = left.getEnvelopeInternal();
100: Envelope envRight = right.getEnvelopeInternal();
101:
102: if (envRight.contains(envLeft) || envLeft.contains(envRight)) {
103: return true;
104: } else if (envRight.intersects(envLeft)) {
105: return left.intersects(right);
106: } else {
107: return false;
108: }
109:
110: // Note that this is a pretty permissive logic
111: // if the type has somehow been mis-set (can't happen externally)
112: // then true is returned in all cases
113: }
114:
115: public Object accept(FilterVisitor visitor, Object extraData) {
116: return visitor.visit(this, extraData);
117: }
118:
119: }
|