001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2005-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.data.postgis;
017:
018: import java.util.ArrayList;
019:
020: import java.util.Iterator;
021: import java.util.List;
022:
023: import org.geotools.data.FeatureReader;
024:
025: import org.geotools.data.Transaction;
026: import org.geotools.feature.Feature;
027: import org.geotools.feature.FeatureCollection;
028: import org.geotools.feature.FeatureType;
029:
030: import org.geotools.filter.FilterFactory;
031: import org.geotools.filter.FilterFactoryFinder;
032: import org.geotools.filter.GeometryFilter;
033:
034: import com.vividsolutions.jts.geom.Envelope;
035:
036: /**
037: * This test should be run against a postgis instance that does not
038: * have GEOS installed.
039: *
040: * @author Justin Deoliveira, The Open Planning Project
041: *
042: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/postgis/src/test/java/org/geotools/data/postgis/PostgisWithoutGeosOnlineTest.java $
043: */
044: public class PostgisWithoutGeosOnlineTest extends
045: AbstractPostgisDataTestCase {
046:
047: public PostgisWithoutGeosOnlineTest(String name) {
048: super (name);
049: }
050:
051: protected void setUp() throws Exception {
052: super .setUp();
053: }
054:
055: public String getFixtureFile() {
056: return "nogeos.properties";
057: }
058:
059: public void _testBboxQuery() throws Exception {
060: // get the bounding box for each feature
061: List bbox = new ArrayList();
062: List fids = new ArrayList();
063: FeatureCollection fc = data.getFeatureSource("road")
064: .getFeatures();
065: for (Iterator itr = fc.iterator(); itr.hasNext();) {
066: Feature f = (Feature) itr.next();
067: bbox.add(f.getDefaultGeometry().getEnvelopeInternal());
068: fids.add(f.getID());
069: }
070:
071: //query each feature
072: FeatureType type = data.getSchema("road");
073: FilterFactory ff = FilterFactoryFinder.createFilterFactory();
074:
075: for (int i = 0; i < bbox.size(); i++) {
076: Envelope box = (Envelope) bbox.get(i);
077: String fid = (String) fids.get(i);
078:
079: GeometryFilter filter = ff
080: .createGeometryFilter(GeometryFilter.GEOMETRY_BBOX);
081:
082: filter.addLeftGeometry(ff.createAttributeExpression(type,
083: "geom"));
084: filter.addRightGeometry(ff.createBBoxExpression(box));
085:
086: FeatureReader reader = ((PostgisDataStore) data)
087: .getFeatureReader(type, filter,
088: Transaction.AUTO_COMMIT);
089: boolean found = false;
090: for (; reader.hasNext();) {
091: Feature f = reader.next();
092: if (fid.equals(f.getID()))
093: found = true;
094: }
095: reader.close();
096: assertTrue(found);
097: }
098: }
099:
100: public void testBboxQueryWithLooseBBOX() throws Exception {
101: ((PostgisDataStore) data).setLooseBbox(true);
102: _testBboxQuery();
103: }
104:
105: public void testBboxQueryWithoutLooseBBOX() throws Exception {
106: ((PostgisDataStore) data).setLooseBbox(false);
107: _testBboxQuery();
108: }
109: }
|