root / branches / Mobile_Compatible_Hito_1 / libFMap_data / src / org / gvsig / data / vectorial / filter / spatial / BBOXImpl.java @ 21563
History | View | Annotate | Download (2.7 KB)
1 |
/*
|
---|---|
2 |
* GeoTools - OpenSource mapping toolkit
|
3 |
* http://geotools.org
|
4 |
* (C) 2006, GeoTools Project Managment Committee (PMC)
|
5 |
*
|
6 |
* This library is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU Lesser General Public
|
8 |
* License as published by the Free Software Foundation;
|
9 |
* version 2.1 of the License.
|
10 |
*
|
11 |
* This library is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 |
* Lesser General Public License for more details.
|
15 |
*/
|
16 |
package org.gvsig.data.vectorial.filter.spatial; |
17 |
|
18 |
import java.awt.geom.Rectangle2D; |
19 |
|
20 |
import org.gvsig.data.vectorial.Feature; |
21 |
import org.gvsig.fmap.geom.Geometry; |
22 |
import org.opengis.filter.FilterFactory; |
23 |
import org.opengis.filter.FilterVisitor; |
24 |
import org.opengis.filter.expression.Expression; |
25 |
import org.opengis.filter.expression.Literal; |
26 |
import org.opengis.filter.expression.PropertyName; |
27 |
import org.opengis.filter.spatial.BBOX; |
28 |
|
29 |
/**
|
30 |
* Returns true if the bbox of the geometry passed as expression intersects
|
31 |
* the bbox passed as parameter
|
32 |
*
|
33 |
* @author jcarras
|
34 |
*
|
35 |
*/
|
36 |
public class BBOXImpl implements BBOX { |
37 |
|
38 |
double minx,miny,maxx,maxy;
|
39 |
Rectangle2D bbox;
|
40 |
/**
|
41 |
* Not currently used
|
42 |
*/
|
43 |
String srs;
|
44 |
Expression expression;
|
45 |
|
46 |
public BBOXImpl(Expression e1, double minx, double miny, double maxx, double maxy, String srs) { |
47 |
|
48 |
expression = e1; |
49 |
this.minx = minx ;
|
50 |
this.maxx = maxx;
|
51 |
this.miny = miny;
|
52 |
this.maxy = maxy;
|
53 |
this.bbox=new Rectangle2D.Double(minx,miny,maxx-minx,maxy-miny); |
54 |
this.srs = srs;
|
55 |
} |
56 |
|
57 |
public String getPropertyName() { |
58 |
if(expression instanceof PropertyName) { |
59 |
PropertyName propertyName = (PropertyName) expression; |
60 |
return propertyName.getPropertyName();
|
61 |
} else {
|
62 |
return null; |
63 |
} |
64 |
} |
65 |
|
66 |
public String getSRS() { |
67 |
return srs;
|
68 |
} |
69 |
|
70 |
public double getMinX() { |
71 |
return minx;
|
72 |
} |
73 |
|
74 |
public double getMinY() { |
75 |
return miny;
|
76 |
} |
77 |
|
78 |
public double getMaxX() { |
79 |
return maxx;
|
80 |
} |
81 |
|
82 |
public double getMaxY() { |
83 |
return maxy;
|
84 |
} |
85 |
|
86 |
public boolean evaluate(Object feature) { |
87 |
Object value = expression.evaluate(feature);
|
88 |
if (!(value instanceof Geometry)) |
89 |
return false; |
90 |
Geometry geom = (Geometry)value; |
91 |
|
92 |
return geom.intersects(bbox);
|
93 |
|
94 |
// Note that this is a pretty permissive logic
|
95 |
// if the type has somehow been mis-set (can't happen externally)
|
96 |
// then true is returned in all cases
|
97 |
} |
98 |
|
99 |
public Object accept(FilterVisitor visitor, Object extraData) { |
100 |
return visitor.visit(this,extraData); |
101 |
} |
102 |
|
103 |
|
104 |
|
105 |
} |