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.validation.ValidationResults;
025:
026: import com.vividsolutions.jts.geom.Envelope;
027: import com.vividsolutions.jts.geom.Geometry;
028: import com.vividsolutions.jts.geom.LineString;
029: import com.vividsolutions.jts.geom.Point;
030:
031: /**
032: * PointCoveredByEndPointOfLineValidation purpose.
033: *
034: * <p>
035: * Checks to ensure the Point is covered by an endpoint of the Line.
036: * </p>
037: *
038: * @author dzwiers, Refractions Research, Inc.
039: * @author $Author: dmzwiers $ (last modification)
040: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/validation/src/main/java/org/geotools/validation/spatial/PointCoveredByEndPointOfLineValidation.java $
041: * @version $Id: PointCoveredByEndPointOfLineValidation.java 22666 2006-11-09 03:50:28Z jgarnett $
042: */
043: public class PointCoveredByEndPointOfLineValidation extends
044: PointLineAbstractValidation {
045: /**
046: * PointCoveredByEndPointOfLineValidation constructor.
047: *
048: * <p>
049: * Description
050: * </p>
051: */
052: public PointCoveredByEndPointOfLineValidation() {
053: super ();
054: }
055:
056: /**
057: * Ensure Point is covered by a Line end point.
058: *
059: * <p></p>
060: *
061: * @param layers a HashMap of key="TypeName" value="FeatureSource"
062: * @param envelope The bounding box of modified features
063: * @param results Storage for the error and warning messages
064: *
065: * @return True if no features intersect. If they do then the validation
066: * failed.
067: *
068: * @throws Exception DOCUMENT ME!
069: *
070: * @see org.geotools.validation.IntegrityValidation#validate(java.util.Map,
071: * com.vividsolutions.jts.geom.Envelope,
072: * org.geotools.validation.ValidationResults)
073: */
074: public boolean validate(Map layers, Envelope envelope,
075: ValidationResults results) throws Exception {
076: FeatureSource lineSource = (FeatureSource) layers
077: .get(getRestrictedLineTypeRef());
078: FeatureSource pointSource = (FeatureSource) layers
079: .get(getPointTypeRef());
080:
081: Object[] points = pointSource.getFeatures().toArray();
082: Object[] lines = lineSource.getFeatures().toArray();
083:
084: if (!envelope.contains(pointSource.getBounds())) {
085: results
086: .error((Feature) points[0],
087: "Point Feature Source is not contained within the Envelope provided.");
088:
089: return false;
090: }
091:
092: if (!envelope.contains(lineSource.getBounds())) {
093: results
094: .error((Feature) lines[0],
095: "Line Feature Source is not contained within the Envelope provided.");
096:
097: return false;
098: }
099:
100: for (int i = 0; i < lines.length; i++) {
101: Feature tmp = (Feature) lines[i];
102: Geometry gt = tmp.getDefaultGeometry();
103:
104: if (gt instanceof LineString) {
105: LineString ls = (LineString) gt;
106: Point str = ls.getStartPoint();
107: Point end = ls.getEndPoint();
108:
109: for (int j = 0; j < points.length; j++) {
110: Feature tmp2 = (Feature) points[j];
111: Geometry gt2 = tmp2.getDefaultGeometry();
112:
113: if (gt2 instanceof Point) {
114: Point pt = (Point) gt2;
115:
116: if (pt.equalsExact(str) || pt.equalsExact(end)) {
117: return true;
118: }
119: }
120: }
121: }
122: }
123:
124: return false;
125: }
126: }
|