001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2004-2006, Geotools Project Managment Committee (PMC)
005: * (C) 2004 TOPP - www.openplans.org
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * Created on Apr 29, 2004
018: */
019: package org.geotools.validation.relate;
020:
021: import java.io.IOException;
022: import java.util.HashMap;
023: import java.util.Map;
024:
025: import org.geotools.data.FeatureSource;
026: import org.geotools.feature.Feature;
027: import org.geotools.feature.FeatureIterator;
028: import org.opengis.filter.Filter;
029:
030: import com.vividsolutions.jts.geom.Envelope;
031:
032: /**
033: * OverlapsIntegrityTest<br>
034: * @author bowens<br>
035: * Created Apr 29, 2004<br>
036: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/validation/src/test/java/org/geotools/validation/relate/OverlapsIntegrityTest.java $
037: * @version <br>
038: *
039: * <b>Puropse:</b><br>
040: * <p>
041: * DOCUMENT ME!!
042: * </p>
043: *
044: * <b>Description:</b><br>
045: * <p>
046: * DOCUMENT ME!!
047: * </p>
048: *
049: * <b>Usage:</b><br>
050: * <p>
051: * DOCUMENT ME!!
052: * </p>
053: */
054: public class OverlapsIntegrityTest extends SpatialTestCase {
055:
056: /**
057: * Constructor for OverlapsIntegrityTest.
058: * @param arg0
059: */
060: public OverlapsIntegrityTest(String arg0) {
061: super (arg0);
062: }
063:
064: public void testOverlapFilter() throws Exception {
065: FeatureSource line = mds.getFeatureSource("line");
066:
067: Filter filter;
068:
069: filter = OverlapsIntegrity.filterBBox(new Envelope(), line
070: .getSchema());
071: assertEquals("with empty envelope", 1, line.getFeatures(filter)
072: .size());
073:
074: filter = OverlapsIntegrity.filterBBox(
075: new Envelope(-1, 3, -2, 3), line.getSchema());
076: assertEquals("with envelope", 4, line.getFeatures(filter)
077: .size());
078:
079: Envelope all = line.getBounds();
080: if (all == null) {
081: // damm lets figure it out
082: all = line.getFeatures().getBounds();
083: }
084: int counter = 0;
085: filter = OverlapsIntegrity.filterBBox(all, line.getSchema());
086: FeatureIterator r = line.getFeatures().features();
087: for (; r.hasNext();) {
088: System.out.println("Loop counter: " + ++counter);
089: Feature victim = r.next();
090: System.out.println("Found line number: " + victim.getID());
091: assertTrue("feature " + victim.getID(), filter
092: .evaluate(victim));
093: }
094: r.close();
095: assertEquals("count of all features", 4, line.getFeatures(
096: filter).size());
097: }
098:
099: public void testValidate() {
100: OverlapsIntegrity overlap = new OverlapsIntegrity();
101: overlap.setExpected(false);
102: overlap.setGeomTypeRefA("my:line");
103:
104: Map map = new HashMap();
105: try {
106: map.put("my:line", mds.getFeatureSource("line"));
107: } catch (IOException e1) {
108: e1.printStackTrace();
109: }
110:
111: try {
112: vr.setValidation(overlap);
113: assertFalse(overlap.validate(map, lineBounds, vr));
114: } catch (Exception e) {
115: e.printStackTrace();
116: }
117: }
118:
119: public void testValidateBBox() {
120: OverlapsIntegrity overlap = new OverlapsIntegrity();
121: overlap.setExpected(false);
122: overlap.setGeomTypeRefA("my:line");
123:
124: System.out.println("=========================================");
125: Map map = new HashMap();
126: try {
127: map.put("my:line", mds.getFeatureSource("line"));
128: } catch (IOException e1) {
129: // TODO Auto-generated catch block
130: e1.printStackTrace();
131: }
132:
133: try {
134: System.out.println("Test Validate BBox");
135: //assertFalse(overlap.validate(map, new Envelope(-1,2,-2,3), vr));
136: assertFalse(overlap.validate(map, lineBounds, vr));
137: //(RoadValidationResults)vr;
138: } catch (Exception e) {
139: e.printStackTrace();
140: }
141: }
142:
143: }
|