001: /*
002: * Geotools2 - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002, 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.renderer.shape;
017:
018: import junit.framework.TestCase;
019:
020: import org.geotools.data.DefaultQuery;
021: import org.geotools.data.FeatureSource;
022: import org.geotools.data.Query;
023: import org.geotools.feature.Feature;
024: import org.geotools.filter.AttributeExpression;
025: import org.geotools.filter.BBoxExpression;
026: import org.geotools.filter.Filter;
027: import org.geotools.filter.GeometryFilter;
028: import org.geotools.map.DefaultMapContext;
029: import org.geotools.renderer.RenderListener;
030: import org.geotools.styling.Style;
031:
032: import com.vividsolutions.jts.geom.Envelope;
033:
034: /**
035: *
036: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/shapefile-renderer/src/test/java/org/geotools/renderer/shape/QueryTest.java $
037: */
038: public class QueryTest extends TestCase {
039: private static final boolean INTERACTIVE = false;
040: private FeatureSource source;
041: private Style style;
042: private DefaultMapContext map;
043: Envelope bounds = new Envelope(-5, 5, -5, 5);
044:
045: protected void setUp() throws Exception {
046: source = TestUtilites.getDataStore("theme1.shp")
047: .getFeatureSource();
048: style = TestUtilites.createTestStyle("theme1", null);
049: map = new DefaultMapContext();
050: map.addLayer(source, style);
051: }
052:
053: public void testFidFilter() throws Exception {
054: Query q = new DefaultQuery("theme1", TestUtilites.filterFactory
055: .createFidFilter("theme1.2"));
056: map.getLayer(0).setQuery(q);
057:
058: ShapefileRenderer renderer = new ShapefileRenderer(map);
059: renderer.addRenderListener(new RenderListener() {
060: public void featureRenderer(Feature feature) {
061: assertEquals("theme1.2", feature.getID());
062: }
063:
064: public void errorOccurred(Exception e) {
065: throw new RuntimeException(e);
066: }
067: });
068: TestUtilites.INTERACTIVE = INTERACTIVE;
069: TestUtilites.showRender("testFidFilter", renderer, 1000,
070: bounds, 1);
071: }
072:
073: public void testBBOXFilter() throws Exception {
074: BBoxExpression bbox = TestUtilites.filterFactory
075: .createBBoxExpression(new Envelope(-4, -2, 0, -3));
076: String geom = source.getSchema().getDefaultGeometry().getName();
077: AttributeExpression geomExpr = TestUtilites.filterFactory
078: .createAttributeExpression(source.getSchema(), geom);
079:
080: GeometryFilter filter = TestUtilites.filterFactory
081: .createGeometryFilter(Filter.GEOMETRY_INTERSECTS);
082: filter.addRightGeometry(bbox);
083: filter.addLeftGeometry(geomExpr);
084:
085: Query q = new DefaultQuery("theme1", filter);
086: map.getLayer(0).setQuery(q);
087:
088: ShapefileRenderer renderer = new ShapefileRenderer(map);
089: renderer.addRenderListener(new RenderListener() {
090: public void featureRenderer(Feature feature) {
091: assertEquals("theme1.1", feature.getID());
092: }
093:
094: public void errorOccurred(Exception e) {
095: throw new RuntimeException(e);
096: }
097: });
098: TestUtilites.showRender("testFidFilter", renderer, 1000,
099: bounds, 1);
100: }
101:
102: }
|