Class TopologyValidationError

  1  
  2  
  3 /*
  4  * Copyright (c) 2016 Vivid Solutions.
  5  *
  6  * All rights reserved. This program and the accompanying materials
  7  * are made available under the terms of the Eclipse Public License 2.0
  8  * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
  9  * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v20.html
 10  * and the Eclipse Distribution License is available at
 11  *
 12  * http://www.eclipse.org/org/documents/edl-v10.php.
 13  */
 14 package org.locationtech.jts.operation.valid;
 15  
 16 import org.locationtech.jts.geom.Coordinate;
 17 import org.locationtech.jts.geom.Geometry;
 18  
 19 /**
 20  * Contains information about the nature and location of a {@link Geometry}
 21  * validation error
 22  *
 23  * @version 1.7
 24  */
 25 public class TopologyValidationError {
 26  
 27   /**
 28    * Not used
 29    * @deprecated
 30    */
 31   public static final int ERROR                   = 0;
 32   /**
 33    * No longer used - repeated points are considered valid as per the SFS
 34    * @deprecated
 35    */
 36   public static final int REPEATED_POINT          = 1;
 37  
 38   /**
 39    * Indicates that a hole of a polygon lies partially or completely in the exterior of the shell
 40    */
 41   public static final int HOLE_OUTSIDE_SHELL      = 2;
 42  
 43   /**
 44    * Indicates that a hole lies in the interior of another hole in the same polygon
 45    */
 46   public static final int NESTED_HOLES            = 3;
 47  
 48   /**
 49    * Indicates that the interior of a polygon is disjoint
 50    * (often caused by set of contiguous holes splitting the polygon into two parts)
 51    */
 52   public static final int DISCONNECTED_INTERIOR   = 4;
 53  
 54   /**
 55    * Indicates that two rings of a polygonal geometry intersect
 56    */
 57   public static final int SELF_INTERSECTION       = 5;
 58  
 59   /**
 60    * Indicates that a ring self-intersects
 61    */
 62   public static final int RING_SELF_INTERSECTION  = 6;
 63  
 64   /**
 65    * Indicates that a polygon component of a MultiPolygon lies inside another polygonal component
 66    */
 67   public static final int NESTED_SHELLS           = 7;
 68  
 69   /**
 70    * Indicates that a polygonal geometry contains two rings which are identical
 71    */
 72   public static final int DUPLICATE_RINGS         = 8;
 73  
 74   /**
 75    * Indicates that either
 76    * <ul>
 77    * <li>a LineString contains a single point
 78    * <li>a LinearRing contains 2 or 3 points
 79    * </ul>
 80    */
 81   public static final int TOO_FEW_POINTS          = 9;
 82  
 83   /**
 84    * Indicates that the <code>X</code> or <code>Y</code> ordinate of
 85    * a Coordinate is not a valid numeric value (e.g. {@link Double#NaN} )
 86    */
 87   public static final int INVALID_COORDINATE      = 10;
 88  
 89   /**
 90    * Indicates that a ring is not correctly closed
 91    * (the first and the last coordinate are different)
 92    */
 93   public static final int RING_NOT_CLOSED      = 11;
 94  
 95   /**
 96    * Messages corresponding to error codes
 97    */
 98   public static final String[] errMsg = {
 99     "Topology Validation Error",
100     "Repeated Point",
101     "Hole lies outside shell",
102     "Holes are nested",
103     "Interior is disconnected",
104     "Self-intersection",
105     "Ring Self-intersection",
106     "Nested shells",
107     "Duplicate Rings",
108     "Too few distinct points in geometry component",
109     "Invalid Coordinate",
110     "Ring is not closed"
111   };
112  
113   private int errorType;
114   private Coordinate pt;
115  
116   /**
117    * Creates a validation error with the given type and location
118    *
119    * @param errorType the type of the error
120    * @param pt the location of the error
121    */
122   public TopologyValidationError(int errorType, Coordinate pt)
123   {
124     this.errorType = errorType;
125     if (pt != null)
126       this.pt = pt.copy();
127   }
128  
129   /**
130    * Creates a validation error of the given type with a null location
131    *
132    * @param errorType the type of the error
133    *
134    */
135   public TopologyValidationError(int errorType)
136   {
137     this(errorType, null);
138   }
139  
140   /**
141    * Returns the location of this error (on the {@link Geometry} containing the error).
142    *
143    * @return a {@link Coordinate} on the input geometry
144    */
145   public Coordinate getCoordinate() { return pt; }
146  
147   /**
148    * Gets the type of this error.
149    *
150    * @return the error type
151    */
152   public int getErrorType() { return errorType; }
153  
154   /**
155    * Gets an error message describing this error.
156    * The error message does not describe the location of the error.
157    *
158    * @return the error message
159    */
160   public String getMessage() { return errMsg[errorType]; }
161  
162   /**
163    * Gets a message describing the type and location of this error.
164    * @return the error message
165    */
166   public String toString()
167   {
168     String locStr = "";
169     if (pt != null)
170       locStr = " at or near point " + pt;
171     return getMessage() + locStr;
172   }
173 }
174