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: * PointCoveredByLineValidation purpose.
035: *
036: * <p>
037: * Checks to ensure the Line is covered by the Polygon Boundary.
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/LineCoveredByPolygonBoundaryValidation.java $
043: * @version $Id: LineCoveredByPolygonBoundaryValidation.java 22666 2006-11-09 03:50:28Z jgarnett $
044: */
045: public class LineCoveredByPolygonBoundaryValidation extends
046: LinePolygonAbstractValidation {
047: /**
048: * PointCoveredByLineValidation constructor.
049: *
050: * <p>
051: * Super
052: * </p>
053: */
054: public LineCoveredByPolygonBoundaryValidation() {
055: super ();
056: }
057:
058: /**
059: * Ensure Line is covered by the Polygon Boundary.
060: *
061: * <p></p>
062: *
063: * @param layers a HashMap of key="TypeName" value="FeatureSource"
064: * @param envelope The bounding box of modified features
065: * @param results Storage for the error and warning messages
066: *
067: * @return True if no features intersect. If they do then the validation
068: * failed.
069: *
070: * @throws Exception DOCUMENT ME!
071: *
072: * @see org.geotools.validation.IntegrityValidation#validate(java.util.Map,
073: * com.vividsolutions.jts.geom.Envelope,
074: * org.geotools.validation.ValidationResults)
075: */
076: public boolean validate(Map layers, Envelope envelope,
077: ValidationResults results) throws Exception {
078:
079: boolean r = true;
080:
081: FeatureSource fsLine = (FeatureSource) layers
082: .get(getLineTypeRef());
083:
084: FeatureCollection fcLine = fsLine.getFeatures();
085: FeatureIterator fLine = fcLine.features();
086:
087: FeatureSource fsPoly = (FeatureSource) layers
088: .get(getRestrictedPolygonTypeRef());
089:
090: FeatureCollection fcPoly = fsPoly.getFeatures();
091:
092: while (fLine.hasNext()) {
093: Feature line = fLine.next();
094: FeatureIterator fPoly = fcPoly.features();
095: Geometry lineGeom = line.getDefaultGeometry();
096: if (envelope.contains(lineGeom.getEnvelopeInternal())) {
097: // check for valid comparison
098: if (LineString.class.isAssignableFrom(lineGeom
099: .getClass())) {
100: while (fPoly.hasNext()) {
101: Feature poly = fPoly.next();
102: Geometry polyGeom = poly.getDefaultGeometry();
103: if (envelope.contains(polyGeom
104: .getEnvelopeInternal())) {
105: if (Polygon.class.isAssignableFrom(polyGeom
106: .getClass())) {
107: Geometry polyGeomBoundary = polyGeom
108: .getBoundary();
109: if (!polyGeomBoundary
110: .contains(lineGeom)) {
111: results
112: .error(poly,
113: "Boundary does not contain the specified Line.");
114: r = false;
115: }
116: // do next.
117: } else {
118: fcPoly.remove(poly);
119: results
120: .warning(poly,
121: "Invalid type: this feature is not a derivative of a Polygon");
122: }
123: } else {
124: fcPoly.remove(poly);
125: }
126: }
127: } else {
128: results
129: .warning(line,
130: "Invalid type: this feature is not a derivative of a LineString");
131: }
132: }
133: }
134: return r;
135: }
136:
137: /**
138: * The priority level used to schedule this Validation.
139: *
140: * @return PRORITY_SIMPLE
141: *
142: * @see org.geotools.validation.Validation#getPriority()
143: */
144: public int getPriority() {
145: return PRIORITY_SIMPLE;
146: }
147: }
|