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