00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 #ifndef GEOS_OPVALID_H
00054 #define GEOS_OPVALID_H
00055
00056 #include <memory>
00057 #include <string>
00058 #include <vector>
00059 #include <map>
00060 #include <geos/platform.h>
00061 #include <geos/opRelate.h>
00062 #include <geos/indexSweepline.h>
00063 #include <geos/indexQuadtree.h>
00064
00065 namespace geos {
00066
00067
00068
00069
00070
00071
00072
00073 class SimpleNestedRingTester {
00074 public:
00075 SimpleNestedRingTester(GeometryGraph *newGraph);
00076 ~SimpleNestedRingTester();
00077 void add(LinearRing *ring);
00078 Coordinate& getNestedPoint();
00079 bool isNonNested();
00080 private:
00081 CGAlgorithms *cga;
00082 GeometryGraph *graph;
00083 vector<LinearRing*> *rings;
00084 Coordinate nestedPt;
00085 };
00086
00087
00088
00089
00090
00091
00092 class TopologyValidationError {
00093 public:
00094 enum {
00095 ERROR,
00096 REPEATED_POINT,
00097 HOLE_OUTSIDE_SHELL,
00098 NESTED_HOLES,
00099 DISCONNECTED_INTERIOR,
00100 SELF_INTERSECTION,
00101 RING_SELF_INTERSECTION,
00102 NESTED_SHELLS,
00103 DUPLICATE_RINGS,
00104 TOO_FEW_POINTS,
00105 INVALID_COORDINATE
00106 };
00107
00108 TopologyValidationError(int newErrorType,Coordinate newPt);
00109 TopologyValidationError(int newErrorType);
00110 Coordinate& getCoordinate();
00111 string getMessage();
00112 int getErrorType();
00113 string toString();
00114 private:
00115 static string errMsg[];
00116 int errorType;
00117 Coordinate pt;
00118 };
00119
00120
00121
00122
00123
00124
00125 class RepeatedPointTester {
00126 public:
00127 RepeatedPointTester() {};
00128 Coordinate& getCoordinate();
00129 bool hasRepeatedPoint(const Geometry *g);
00130 bool hasRepeatedPoint(const CoordinateSequence *coord);
00131 private:
00132 Coordinate repeatedCoord;
00133 bool hasRepeatedPoint(const Polygon *p);
00134 bool hasRepeatedPoint(const GeometryCollection *gc);
00135 bool hasRepeatedPoint(const MultiPolygon *gc);
00136 bool hasRepeatedPoint(const MultiLineString *gc);
00137 };
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 class ConsistentAreaTester {
00153 private:
00154 LineIntersector *li;
00155 GeometryGraph *geomGraph;
00156 RelateNodeGraph *nodeGraph;
00157
00158 Coordinate invalidPoint;
00163 bool isNodeEdgeAreaLabelsConsistent();
00164 public:
00165 ConsistentAreaTester(GeometryGraph *newGeomGraph);
00166 ~ConsistentAreaTester();
00170 Coordinate& getInvalidPoint();
00171 bool isNodeConsistentArea();
00187 bool hasDuplicateRings();
00188 };
00189
00190
00191
00192
00193
00194
00195
00196
00197 class SweeplineNestedRingTester {
00198 public:
00199 SweeplineNestedRingTester(GeometryGraph *newGraph);
00200 ~SweeplineNestedRingTester();
00201 Coordinate& getNestedPoint();
00202 void add(LinearRing* ring);
00203 bool isNonNested();
00204 bool isInside(LinearRing *innerRing,LinearRing *searchRing);
00205 class OverlapAction: public SweepLineOverlapAction {
00206 public:
00207 bool isNonNested;
00208 OverlapAction(SweeplineNestedRingTester *p);
00209 void overlap(SweepLineInterval *s0, SweepLineInterval *s1);
00210 private:
00211 SweeplineNestedRingTester *parent;
00212 };
00213 private:
00214 CGAlgorithms *cga;
00215 GeometryGraph *graph;
00216 vector<LinearRing*> *rings;
00217 Envelope *totalEnv;
00218 SweepLineIndex *sweepLine;
00219 Coordinate nestedPt;
00220 void buildIndex();
00221 };
00222
00223
00224
00225
00226
00227
00228
00229 class QuadtreeNestedRingTester {
00230 public:
00231 QuadtreeNestedRingTester(GeometryGraph *newGraph);
00232 virtual ~QuadtreeNestedRingTester();
00233 Coordinate& getNestedPoint();
00234 void add(LinearRing *ring);
00235 bool isNonNested();
00236 private:
00237 GeometryGraph *graph;
00238 vector<LinearRing*> *rings;
00239 Envelope *totalEnv;
00240 Quadtree *qt;
00241 Coordinate nestedPt;
00242 void buildQuadtree();
00243 };
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257 class ConnectedInteriorTester {
00258 public:
00259 ConnectedInteriorTester(GeometryGraph *newGeomGraph);
00260 ~ConnectedInteriorTester();
00261 Coordinate& getCoordinate();
00262 bool isInteriorsConnected();
00263 static const Coordinate& findDifferentPoint(const CoordinateSequence *coord, const Coordinate& pt);
00264 private:
00265 GeometryFactory *geometryFactory;
00266 CGAlgorithms *cga;
00267 GeometryGraph *geomGraph;
00268
00269
00270 Coordinate disconnectedRingcoord;
00271 void setAllEdgesInResult(PlanarGraph *graph);
00272 vector<EdgeRing*>* buildEdgeRings(vector<EdgeEnd*> *dirEdges);
00277 void visitShellInteriors(const Geometry *g, PlanarGraph *graph);
00278 void visitInteriorRing(const LineString *ring, PlanarGraph *graph);
00289 bool hasUnvisitedShellEdge(vector<EdgeRing*> *edgeRings);
00290 protected:
00291 void visitLinkedDirectedEdges(DirectedEdge *start);
00292 };
00293
00294
00295
00296
00297
00298
00299 class IsValidOp {
00300 friend class Unload;
00301 public:
00308 static const Coordinate& findPtNotNode(const CoordinateSequence *testCoords,const LinearRing *searchRing, GeometryGraph *graph);
00309
00318 static bool isValid(const Coordinate &coord);
00319
00320 IsValidOp(const Geometry *geom);
00321 virtual ~IsValidOp();
00322 bool isValid();
00323 TopologyValidationError* getValidationError();
00324 private:
00325 const Geometry *parentGeometry;
00326 bool isChecked;
00327 TopologyValidationError* validErr;
00328 void checkValid(const Geometry *g);
00329 void checkValid(const Point *g);
00330 void checkValid(const LinearRing *g);
00331 void checkValid(const LineString *g);
00332 void checkValid(const Polygon *g);
00333 void checkValid(const MultiPolygon *g);
00334 void checkValid(const GeometryCollection *gc);
00335 void checkConsistentArea(GeometryGraph *graph);
00336 void checkNoSelfIntersectingRings(GeometryGraph *graph);
00342 void checkSelfIntersectingRing(EdgeIntersectionList *eiList);
00343 void checkTooFewPoints(GeometryGraph *graph);
00352 void checkHolesInShell(const Polygon *p,GeometryGraph *graph);
00353
00366 void checkHolesNotNested(const Polygon *p,GeometryGraph *graph);
00367
00381 void checkShellsNotNested(const MultiPolygon *mp,GeometryGraph *graph);
00391 void checkShellNotNested(const LinearRing *shell,const Polygon *p,GeometryGraph *graph);
00395 const Coordinate& checkShellInsideHole(const LinearRing *shell,const LinearRing *hole,GeometryGraph *graph);
00396 void checkConnectedInteriors(GeometryGraph *graph);
00397 void checkInvalidCoordinates(const CoordinateSequence *cs);
00398 void checkInvalidCoordinates(const Polygon *poly);
00399 };
00400
00401 }
00402 #endif