01: package org.geotools.renderer.shape;
02:
03: import java.awt.geom.AffineTransform;
04:
05: import junit.framework.TestCase;
06:
07: import org.geotools.factory.CommonFactoryFinder;
08: import org.geotools.referencing.crs.DefaultGeographicCRS;
09: import org.geotools.referencing.operation.DefaultMathTransformFactory;
10: import org.geotools.referencing.operation.matrix.GeneralMatrix;
11: import org.opengis.filter.FilterFactory;
12: import org.opengis.filter.Or;
13: import org.opengis.filter.expression.Literal;
14: import org.opengis.filter.spatial.BBOX;
15: import org.opengis.referencing.operation.MathTransform;
16:
17: import com.vividsolutions.jts.geom.Envelope;
18: import com.vividsolutions.jts.geom.Geometry;
19: import com.vividsolutions.jts.geom.GeometryFactory;
20:
21: public class FilterTransformerTest extends TestCase {
22:
23: private static final String DEFAULT = "4326";
24: private FilterTransformer filterTransformer;
25: private final FilterFactory filterFactory = CommonFactoryFinder
26: .getFilterFactory(null);
27:
28: protected void setUp() throws Exception {
29: super .setUp();
30: AffineTransform t = AffineTransform
31: .getTranslateInstance(10, 10);
32: DefaultMathTransformFactory fac = new DefaultMathTransformFactory();
33: MathTransform mt = fac.createAffineTransform(new GeneralMatrix(
34: t));
35: filterTransformer = new FilterTransformer(mt);
36: }
37:
38: public void testVisitBBoxExpression() throws Exception {
39: Envelope envelope = new Envelope(0, 10, 0, 10);
40: GeometryFactory geometryFactory = new GeometryFactory();
41: Literal lit = filterFactory.literal(geometryFactory
42: .toGeometry(envelope));
43: lit = (Literal) lit.accept(filterTransformer, null);
44: assertTrue(geometryFactory.toGeometry(
45: new Envelope(10, 20, 10, 20)).equals(
46: (Geometry) lit.getValue()));
47: }
48:
49: public void testVisitCompareFilter() throws Exception {
50: BBOX filter = filterFactory.bbox("geom", 0, 0, 10, 10, DEFAULT);
51:
52: BBOX result = (BBOX) filter.accept(filterTransformer, null);
53: assertEquals(10.0, result.getMinX(), 0.000001);
54: assertEquals(10.0, result.getMinY(), 0.000001);
55: assertEquals(20.0, result.getMaxX(), 0.000001);
56: assertEquals(20.0, result.getMaxY(), 0.000001);
57: }
58:
59: public void testVisitORFilter() throws Exception {
60: BBOX bbox1 = filterFactory.bbox("geom", 0, 0, 10, 10, DEFAULT);
61: BBOX bbox2 = filterFactory
62: .bbox("geom", 10, 10, 20, 20, DEFAULT);
63:
64: Or or = filterFactory.or(bbox1, bbox2);
65: // TEST filter.None because it was a bug before
66: or = (Or) or.accept(filterTransformer, null);
67:
68: bbox1 = (BBOX) or.getChildren().get(0);
69: bbox2 = (BBOX) or.getChildren().get(1);
70:
71: assertEquals(10.0, bbox1.getMinX(), 0.000001);
72: assertEquals(10.0, bbox1.getMinY(), 0.000001);
73: assertEquals(20.0, bbox1.getMaxX(), 0.000001);
74: assertEquals(20.0, bbox1.getMaxY(), 0.000001);
75:
76: assertEquals(20.0, bbox2.getMinX(), 0.000001);
77: assertEquals(20.0, bbox2.getMinY(), 0.000001);
78: assertEquals(30.0, bbox2.getMaxX(), 0.000001);
79: assertEquals(30.0, bbox2.getMaxY(), 0.000001);
80: }
81:
82: }
|