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.Coordinate;
029: import com.vividsolutions.jts.geom.Envelope;
030: import com.vividsolutions.jts.geom.Geometry;
031: import com.vividsolutions.jts.geom.LineSegment;
032: import com.vividsolutions.jts.geom.LineString;
033:
034: /**
035: * PointCoveredByLineValidation purpose.
036: *
037: * <p>
038: * Checks to ensure the Line does not have a psuedo-node.
039: * </p>
040: *
041: * @author dzwiers, Refractions Research, Inc.
042: * @author $Author: dmzwiers $ (last modification)
043: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/validation/src/main/java/org/geotools/validation/spatial/LineNoPseudoNodeValidation.java $
044: * @version $Id: LineNoPseudoNodeValidation.java 22666 2006-11-09 03:50:28Z jgarnett $
045: */
046: public class LineNoPseudoNodeValidation extends LineAbstractValidation {
047:
048: private int degreesAllowable;
049:
050: /**
051: * PointCoveredByLineValidation constructor.
052: *
053: * <p>
054: * Super
055: * </p>
056: */
057: public LineNoPseudoNodeValidation() {
058: super ();
059: }
060:
061: /**
062: * Ensure Line does not have a psuedo-node.
063: *
064: * <p></p>
065: *
066: * @param layers a HashMap of key="TypeName" value="FeatureSource"
067: * @param envelope The bounding box of modified features
068: * @param results Storage for the error and warning messages
069: *
070: * @return True if no features intersect. If they do then the validation
071: * failed.
072: *
073: * @throws Exception DOCUMENT ME!
074: *
075: * @see org.geotools.validation.IntegrityValidation#validate(java.util.Map,
076: * com.vividsolutions.jts.geom.Envelope,
077: * org.geotools.validation.ValidationResults)
078: */
079: public boolean validate(Map layers, Envelope envelope,
080: ValidationResults results) throws Exception {
081:
082: boolean r = true;
083:
084: FeatureSource fsLine = (FeatureSource) layers
085: .get(getLineTypeRef());
086: FeatureCollection fcLine = fsLine.getFeatures();
087: FeatureIterator fLine = fcLine.features();
088:
089: while (fLine.hasNext()) {
090: Feature line = fLine.next();
091: Geometry lineGeom = line.getDefaultGeometry();
092: if (envelope.contains(lineGeom.getEnvelopeInternal())) {
093: // check for valid comparison
094: if (LineString.class.isAssignableFrom(lineGeom
095: .getClass())) {
096: Coordinate[] c = lineGeom.getCoordinates();
097: int i = 0;
098: while (i + 2 < c.length) {
099: LineSegment ls1 = new LineSegment(c[i],
100: c[i + 1]);
101: LineSegment ls2 = new LineSegment(c[i + 1],
102: c[i + 2]);
103: double a1 = ls1.angle();
104: double a2 = ls2.angle();
105: if (!((a1 - degreesAllowable) < a1 && (a1 + degreesAllowable) > a2)) {
106: results
107: .error(
108: line,
109: "Atleast one node was too close to the other the perpendicular line between the node's two neighbours.");
110: i = c.length;
111: }
112: }
113: } else {
114: results
115: .warning(line,
116: "Invalid type: this feature is not a derivative of a LineString");
117: }
118: }
119: }
120: return r;
121: }
122:
123: /**
124: * Access degreesAllowable property.
125: *
126: * @return Returns the degreesAllowable.
127: */
128: public int getDegreesAllowable() {
129: return degreesAllowable;
130: }
131:
132: /**
133: * Set degreesAllowable to degreesAllowable.
134: *
135: * @param degreesAllowable The degreesAllowable to set.
136: */
137: public void setDegreesAllowable(int degreesAllowable) {
138: this.degreesAllowable = degreesAllowable;
139: }
140: }
|