01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2004-2006, Geotools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * Created on Jan 24, 2004
17: */
18: package org.geotools.validation.spatial;
19:
20: import org.geotools.feature.Feature;
21: import org.geotools.feature.FeatureType;
22: import org.geotools.validation.DefaultFeatureValidation;
23: import org.geotools.validation.ValidationResults;
24:
25: import com.vividsolutions.jts.geom.Geometry;
26: import com.vividsolutions.jts.geom.Polygon;
27:
28: /**
29: * PolygonNoGapsValidation purpose.
30: *
31: * <p>
32: * Ensures Polygon does not have gaps.
33: * </p>
34: *
35: * @author dzwiers, Refractions Research, Inc.
36: * @author $Author: dmzwiers $ (last modification)
37: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/validation/src/main/java/org/geotools/validation/spatial/PolygonNoGapsValidation.java $
38: * @version $Id: PolygonNoGapsValidation.java 22226 2006-10-18 20:06:40Z acuster $
39: */
40: public class PolygonNoGapsValidation extends DefaultFeatureValidation {
41: /**
42: * PolygonNoGapsValidation constructor.
43: *
44: * <p>
45: * Description
46: * </p>
47: */
48: public PolygonNoGapsValidation() {
49: super ();
50: }
51:
52: /**
53: * Ensure Polygon does not have gaps.
54: *
55: * <p></p>
56: *
57: * @param feature the Feature to be validated
58: * @param type the FeatureType of the feature
59: * @param results storage for the error and warning messages
60: *
61: * @return True if no features intersect. If they do then the validation
62: * failed.
63: *
64: * @throws Exception DOCUMENT ME!
65: *
66: * @see org.geotools.validation.IntegrityValidation#validate(java.util.Map,
67: * com.vividsolutions.jts.geom.Envelope,
68: * org.geotools.validation.ValidationResults)
69: */
70: public boolean validate(Feature feature, FeatureType type,
71: ValidationResults results) {
72:
73: if (feature != null) {
74: Geometry layer = feature.getDefaultGeometry();
75: if (layer instanceof Polygon) {
76: Polygon p = (Polygon) layer;
77: if (p.getNumInteriorRing() != 0) {
78: results.error(feature,
79: "The generated result was had gaps.");
80: return false;
81: }
82: return true;
83: }
84: results.error(feature,
85: "The generated result was not of type polygon.");
86: return false;
87: }
88:
89: return true;
90: }
91: }
|