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: package org.geotools.validation.spatial;
017:
018: import java.util.Map;
019: import java.util.logging.Logger;
020:
021: import org.geotools.data.FeatureSource;
022: import org.geotools.feature.Feature;
023: import org.geotools.feature.FeatureCollection;
024: import org.geotools.validation.ValidationResults;
025:
026: import com.vividsolutions.jts.geom.Envelope;
027: import com.vividsolutions.jts.geom.Geometry;
028:
029: /**
030: * PolygonBoundaryCoveredByPolygonValidation purpose.
031: *
032: * <p>
033: * Ensures Polygon Boundary is not covered by the Polygon.
034: * </p>
035: *
036: * @author dzwiers, Refractions Research, Inc.
037: * @author $Author: jive $ (last modification)
038: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/validation/src/main/java/org/geotools/validation/spatial/PolygonNotOverlappingPolygonValidation.java $
039: * @version $Id: PolygonNotOverlappingPolygonValidation.java 27862 2007-11-12 19:51:19Z desruisseaux $
040: */
041: public class PolygonNotOverlappingPolygonValidation extends
042: PolygonPolygonAbstractValidation {
043:
044: private static final Logger LOGGER = org.geotools.util.logging.Logging
045: .getLogger("org.geotools.validation");
046:
047: /**
048: * PolygonBoundaryCoveredByPolygonValidation constructor.
049: *
050: * <p>
051: * Description
052: * </p>
053: */
054: public PolygonNotOverlappingPolygonValidation() {
055: super ();
056:
057: // TODO Auto-generated constructor stub
058: }
059:
060: /**
061: * Ensure Polygon Boundary is not covered by the Polygon.
062: *
063: * <p></p>
064: *
065: * @param layers a HashMap of key="TypeName" value="FeatureSource"
066: * @param envelope The bounding box of modified features
067: * @param results Storage for the error and warning messages
068: *
069: * @return True if no features intersect. If they do then the validation
070: * failed.
071: *
072: * @throws Exception DOCUMENT ME!
073: *
074: * @see org.geotools.validation.IntegrityValidation#validate(java.util.Map,
075: * com.vividsolutions.jts.geom.Envelope,
076: * org.geotools.validation.ValidationResults)
077: */
078: public boolean validate(Map layers, Envelope envelope,
079: ValidationResults results) throws Exception {
080:
081: LOGGER.finer("Starting test " + getName() + " ("
082: + getClass().getName() + ")");
083: String typeRef1 = getPolygonTypeRef();
084: LOGGER.finer(typeRef1 + ": looking up FeatureSource ");
085: FeatureSource polySource1 = (FeatureSource) layers
086: .get(typeRef1);
087: LOGGER.finer(typeRef1 + ": found "
088: + polySource1.getSchema().getTypeName());
089:
090: FeatureCollection collection1 = polySource1.getFeatures(); // limit with envelope
091: Object[] poly1 = collection1.toArray();
092:
093: String typeRef2 = getRestrictedPolygonTypeRef();
094: LOGGER.finer(typeRef2 + ": looking up FeatureSource ");
095: FeatureSource polySource2 = (FeatureSource) layers
096: .get(typeRef2);
097: LOGGER.finer(typeRef2 + ": found "
098: + polySource2.getSchema().getTypeName());
099:
100: FeatureCollection collection2 = polySource2.getFeatures(); // limit with envelope
101: Object[] poly2 = collection2.toArray();
102:
103: /* if (!envelope.contains(collection1.getBounds())) {
104: results.error((Feature) poly1[0],
105: "Polygon Feature Source is not contained within the Envelope provided.");
106: return false;
107: }
108:
109: if (!envelope.contains(collection2.getBounds())) {
110: results.error((Feature) poly2[0],
111: "Restricted Polygon Feature Source is not contained within the Envelope provided.");
112: return true;
113: }*/
114: boolean success = true;
115: for (int i = 0; i < poly1.length; i++) {
116: Feature tmp = (Feature) poly1[i];
117: LOGGER.finest("Polgon overlap test for:" + tmp.getID());
118: Geometry gt = tmp.getDefaultGeometry();
119:
120: for (int j = 0; j < poly2.length; j++) {
121: Feature tmp2 = (Feature) poly2[j];
122: LOGGER.finest("Polgon overlap test against:"
123: + tmp2.getID());
124: Geometry gt2 = tmp2.getDefaultGeometry();
125:
126: if (gt2.overlaps(gt) != expected) {
127: results.error(tmp, "Polygon " + typeRef1
128: + " overlapped Polygon " + typeRef2 + "("
129: + tmp2.getID() + ") was not " + expected);
130: success = false;
131: }
132: }
133: }
134: return success;
135: }
136:
137: boolean expected = true;
138: }
|