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