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: * PolygonCoveredByPolygonValidation purpose.
031: *
032: * <p>
033: * Checks to ensure the Polygon is covered by the Polygon.
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/PolygonCoveredByPolygonValidation.java $
039: * @version $Id: PolygonCoveredByPolygonValidation.java 22666 2006-11-09 03:50:28Z jgarnett $
040: */
041: public class PolygonCoveredByPolygonValidation extends
042: PolygonPolygonAbstractValidation {
043: /**
044: * PointCoveredByLineValidation constructor.
045: *
046: * <p>
047: * Super
048: * </p>
049: */
050: public PolygonCoveredByPolygonValidation() {
051: super ();
052: }
053:
054: /**
055: * Ensure Polygon is covered by the Polygon.
056: *
057: * <p></p>
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 polySource1 = (FeatureSource) layers
075: .get(getPolygonTypeRef());
076: FeatureSource polySource2 = (FeatureSource) layers
077: .get(getRestrictedPolygonTypeRef());
078:
079: Object[] poly1 = polySource1.getFeatures().toArray();
080: Object[] poly2 = polySource2.getFeatures().toArray();
081:
082: if (!envelope.contains(polySource1.getBounds())) {
083: results
084: .error((Feature) poly1[0],
085: "Polygon Feature Source is not contained within the Envelope provided.");
086:
087: return false;
088: }
089:
090: if (!envelope.contains(polySource2.getBounds())) {
091: results
092: .error(
093: (Feature) poly1[0],
094: "Restricted Polygon Feature Source is not contained within the Envelope provided.");
095:
096: return false;
097: }
098:
099: for (int i = 0; i < poly2.length; i++) {
100: Feature tmp = (Feature) poly2[i];
101: Geometry gt = tmp.getDefaultGeometry();
102:
103: for (int j = 0; j < poly1.length; j++) {
104: Feature tmp2 = (Feature) poly1[j];
105: Geometry gt2 = tmp2.getDefaultGeometry();
106:
107: if (gt2.within(gt)) {
108: return true;
109: }
110: }
111: }
112:
113: return false;
114: }
115: }
|