001: /*
002: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
003: * for visualizing and manipulating spatial features with geometry and attributes.
004: *
005: * Copyright (C) 2003 Vivid Solutions
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: *
021: * For more information, contact:
022: *
023: * Vivid Solutions
024: * Suite #1A
025: * 2328 Government Street
026: * Victoria BC V8T 5G5
027: * Canada
028: *
029: * (250)385-6040
030: * www.vividsolutions.com
031: */
032:
033: package com.vividsolutions.jump.qa;
034:
035: import com.vividsolutions.jts.geom.Coordinate;
036: import com.vividsolutions.jts.geom.Geometry;
037: import com.vividsolutions.jump.feature.Feature;
038: import com.vividsolutions.jump.geom.InteriorPointFinder;
039:
040: /**
041: * An error with a Feature, found by Validator.
042: * @see Validator
043: */
044: public class ValidationError {
045: private static InteriorPointFinder interiorPointFinder = new InteriorPointFinder();
046: private ValidationErrorType type;
047: private Feature feature;
048: private Coordinate location;
049:
050: /**
051: * Creates a ValidationError with location unspecified.
052: * @param type the kind of error found
053: * @param feature the feature with the error
054: */
055: public ValidationError(ValidationErrorType type, Feature feature) {
056: this (type, feature, location(feature.getGeometry()));
057: }
058:
059: /**
060: * Creates a ValidationError.
061: * @param type the kind of error found
062: * @param feature the feature with the error
063: * @param location a point near the error
064: */
065: public ValidationError(ValidationErrorType type, Feature feature,
066: Coordinate location) {
067: this .type = type;
068: this .feature = feature;
069: this .location = location;
070: }
071:
072: /**
073: * Creates a ValidationError with location unspecified.
074: * @param type the kind of error found
075: * @param feature the feature with the error
076: * @param badPart the part of the feature having the error
077: */
078: public ValidationError(ValidationErrorType type, Feature feature,
079: Geometry badPart) {
080: this (type, feature, location(badPart));
081: }
082:
083: /**
084: * Returns the kind of error found.
085: * @return the kind of error found
086: */
087: public ValidationErrorType getType() {
088: return type;
089: }
090:
091: /**
092: * Returns a description of the error.
093: * @return a description of the error
094: */
095: public String getMessage() {
096: return type.getMessage();
097: }
098:
099: /**
100: * Returns the feature with the error.
101: * @return the feature with the error
102: */
103: public Feature getFeature() {
104: return feature;
105: }
106:
107: /**
108: * Returns a point near the error.
109: * @return a point near the error
110: */
111: public Coordinate getLocation() {
112: return location;
113: }
114:
115: private static Coordinate location(Geometry g) {
116: try {
117: return interiorPointFinder.findPoint(g);
118: } catch (Exception ex) {
119: //InteriorPointFinder may fail because the geometry has bad topology [Jon Aquino]
120: return interiorPointFinder.centre(g.getEnvelopeInternal());
121: }
122: }
123: }
|