001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2004-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; either
009: * version 2.1 of the License, or (at your option) any later version.
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: * Created on Jan 24, 2004
017: */
018: package org.geotools.validation.spatial;
019:
020: import java.util.Map;
021:
022: import org.geotools.data.FeatureSource;
023: import org.geotools.feature.Feature;
024: import org.geotools.feature.FeatureCollection;
025: import org.geotools.feature.FeatureIterator;
026: import org.geotools.validation.ValidationResults;
027:
028: import com.vividsolutions.jts.geom.Envelope;
029: import com.vividsolutions.jts.geom.Geometry;
030: import com.vividsolutions.jts.geom.LineString;
031: import com.vividsolutions.jts.geom.Polygon;
032:
033: /**
034: * PolygonNotOverlappingLineValidation purpose.
035: *
036: * <p>
037: * Checks that the line is not touching the interior of the polygon.
038: * </p>
039: *
040: * @author dzwiers, Refractions Research, Inc.
041: * @author $Author: dmzwiers $ (last modification)
042: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/validation/src/main/java/org/geotools/validation/spatial/LineNotTouchingPolygonInteriorValidation.java $
043: * @version $Id: LineNotTouchingPolygonInteriorValidation.java 22666 2006-11-09 03:50:28Z jgarnett $
044: */
045: public class LineNotTouchingPolygonInteriorValidation extends
046: LinePolygonAbstractValidation {
047: /**
048: * PolygonNotOverlappingLineValidation constructor.
049: *
050: * <p>
051: * Description
052: * </p>
053: */
054: public LineNotTouchingPolygonInteriorValidation() {
055: super ();
056: }
057:
058: /**
059: * Check that the line is not touching the interior of the polygon.
060: *
061: * @param layers Map of FeatureSource by "dataStoreID:typeName"
062: * @param envelope The bounding box that encloses the unvalidated data
063: * @param results Used to coallate results information
064: *
065: * @return <code>true</code> if all the features pass this test.
066: *
067: * @throws Exception DOCUMENT ME!
068: */
069: public boolean validate(Map layers, Envelope envelope,
070: ValidationResults results) throws Exception {
071: boolean r = true;
072:
073: FeatureSource fsLine = (FeatureSource) layers
074: .get(getLineTypeRef());
075: if (fsLine == null)
076: return true;
077: FeatureCollection fcLine = fsLine.getFeatures();
078: FeatureIterator fLine = fcLine.features();
079:
080: FeatureSource fsPoly = (FeatureSource) layers
081: .get(getRestrictedPolygonTypeRef());
082: if (fsPoly == null)
083: return true;
084: FeatureCollection fcPoly = fsPoly.getFeatures();
085:
086: while (fLine.hasNext()) {
087: Feature line = fLine.next();
088: FeatureIterator fPoly = fcPoly.features();
089: Geometry lineGeom = line.getDefaultGeometry();
090: if (envelope.contains(lineGeom.getEnvelopeInternal())) {
091: // check for valid comparison
092: if (LineString.class.isAssignableFrom(lineGeom
093: .getClass())) {
094: while (fPoly.hasNext()) {
095: Feature poly = fPoly.next();
096: Geometry polyGeom = poly.getDefaultGeometry();
097: if (envelope.contains(polyGeom
098: .getEnvelopeInternal())) {
099: if (Polygon.class.isAssignableFrom(polyGeom
100: .getClass())) {
101: Polygon p = (Polygon) polyGeom;
102: for (int i = 0; i < p
103: .getNumInteriorRing(); i++) {
104: if (!p.getInteriorRingN(i).touches(
105: lineGeom)) {
106: results
107: .error(poly,
108: "Polygon interior touches the specified Line.");
109: }
110: }
111: // do next.
112: } else {
113: fcPoly.remove(poly);
114: results
115: .warning(poly,
116: "Invalid type: this feature is not a derivative of a Polygon");
117: }
118: } else {
119: fcPoly.remove(poly);
120: }
121: }
122: } else {
123: results
124: .warning(line,
125: "Invalid type: this feature is not a derivative of a LineString");
126: }
127: }
128: }
129: return r;
130: }
131: }
|