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.Point;
032:
033: /**
034: * PointCoveredByLineValidation purpose.
035: *
036: * <p>
037: * Checks to ensure the Line End Point is covered by the Line.
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/LineEndPointCoveredByLineValidation.java $
043: * @version $Id: LineEndPointCoveredByLineValidation.java 22666 2006-11-09 03:50:28Z jgarnett $
044: */
045: public class LineEndPointCoveredByLineValidation extends
046: LineLineAbstractValidation {
047: /**
048: * PointCoveredByLineValidation constructor.
049: *
050: * <p>
051: * Super
052: * </p>
053: */
054: public LineEndPointCoveredByLineValidation() {
055: super ();
056: }
057:
058: /**
059: * Ensure Line End Point is covered by the Line.
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 fsRLine = (FeatureSource) layers
088: .get(getRestrictedLineTypeRef());
089:
090: FeatureCollection fcRLine = fsRLine.getFeatures();
091:
092: while (fLine.hasNext()) {
093: Feature line = fLine.next();
094: FeatureIterator fRLine = fcRLine.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 (fRLine.hasNext()) {
101: Feature rLine = fRLine.next();
102: Geometry rLineGeom = rLine.getDefaultGeometry();
103: if (envelope.contains(rLineGeom
104: .getEnvelopeInternal())) {
105: if (LineString.class
106: .isAssignableFrom(rLineGeom
107: .getClass())) {
108: Point p1 = ((LineString) rLineGeom)
109: .getEndPoint();
110: //Point p2 = ((LineString)rLineGeom).getStartPoint(); //include this?
111: if (!lineGeom.contains(p1)) {
112: //if(!(lineGeom.contains(p1) || lineGeom.contains(p2))){
113: results
114: .error(rLine,
115: "Line End Point not covered by the specified Line.");
116: r = false;
117: }
118: // do next.
119: } else {
120: fcRLine.remove(rLine);
121: results
122: .warning(rLine,
123: "Invalid type: this feature is not a derivative of a LineString");
124: }
125: } else {
126: fcRLine.remove(rLine);
127: }
128: }
129: } else {
130: results
131: .warning(line,
132: "Invalid type: this feature is not a derivative of a LineString");
133: }
134: }
135: }
136: return r;
137: }
138: }
|