00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef GEOS_OP_OVERLAY_OVERLAYOP_H
00021 #define GEOS_OP_OVERLAY_OVERLAYOP_H
00022
00023 #include <geos/export.h>
00024
00025 #include <geos/operation/GeometryGraphOperation.h>
00026 #include <geos/geomgraph/EdgeList.h>
00027 #include <geos/algorithm/PointLocator.h>
00028 #include <geos/geomgraph/PlanarGraph.h>
00029
00030 #include <vector>
00031
00032
00033 namespace geos {
00034 namespace geom {
00035 class Geometry;
00036 class Coordinate;
00037 class GeometryFactory;
00038 class Polygon;
00039 class LineString;
00040 class Point;
00041 }
00042 namespace geomgraph {
00043 class Label;
00044 class Edge;
00045 class Node;
00046 }
00047 namespace operation {
00048 namespace overlay {
00049 class ElevationMatrix;
00050 }
00051 }
00052 }
00053
00054 namespace geos {
00055 namespace operation {
00056 namespace overlay {
00057
00059
00063 class GEOS_DLL OverlayOp: public GeometryGraphOperation {
00064
00065 public:
00066
00068
00072 enum OpCode {
00073 opINTERSECTION=1,
00074 opUNION,
00075 opDIFFERENCE,
00076 opSYMDIFFERENCE
00077 };
00078
00079 static geom::Geometry* overlayOp(const geom::Geometry *geom0,
00080 const geom::Geometry *geom1,
00081 OpCode opCode);
00082
00083
00084 static bool isResultOfOp(geomgraph::Label *label, OpCode opCode);
00085
00087
00090 static bool isResultOfOp(int loc0, int loc1, OpCode opCode);
00091
00093
00097 OverlayOp(const geom::Geometry *g0, const geom::Geometry *g1);
00098
00099 virtual ~OverlayOp();
00100
00101 geom::Geometry* getResultGeometry(OpCode funcCode);
00102
00103
00104 geomgraph::PlanarGraph& getGraph() { return graph; }
00105
00113 bool isCoveredByLA(const geom::Coordinate& coord);
00114
00121 bool isCoveredByA(const geom::Coordinate& coord);
00122
00123
00124
00125
00126
00127
00128 protected:
00129
00138 void insertUniqueEdge(geomgraph::Edge *e);
00139
00140 private:
00141
00142 algorithm::PointLocator ptLocator;
00143
00144 const geom::GeometryFactory *geomFact;
00145
00146 geom::Geometry *resultGeom;
00147
00148 geomgraph::PlanarGraph graph;
00149
00150 geomgraph::EdgeList edgeList;
00151
00152 std::vector<geom::Polygon*> *resultPolyList;
00153
00154 std::vector<geom::LineString*> *resultLineList;
00155
00156 std::vector<geom::Point*> *resultPointList;
00157
00158 void computeOverlay(OpCode opCode);
00159
00160 void insertUniqueEdges(std::vector<geomgraph::Edge*> *edges);
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00182 void computeLabelsFromDepths();
00183
00188 void replaceCollapsedEdges();
00189
00200 void copyPoints(int argIndex);
00201
00210 void computeLabelling();
00211
00219 void mergeSymLabels();
00220
00221 void updateNodeLabelling();
00222
00240 void labelIncompleteNodes();
00241
00245 void labelIncompleteNode(geomgraph::Node *n, int targetIndex);
00246
00258 void findResultAreaEdges(OpCode opCode);
00259
00264 void cancelDuplicateResultEdges();
00265
00270 bool isCovered(const geom::Coordinate& coord,
00271 std::vector<geom::Geometry*> *geomList);
00272
00277 bool isCovered(const geom::Coordinate& coord,
00278 std::vector<geom::Polygon*> *geomList);
00279
00284 bool isCovered(const geom::Coordinate& coord,
00285 std::vector<geom::LineString*> *geomList);
00286
00291 geom::Geometry* computeGeometry(
00292 std::vector<geom::Point*> *nResultPointList,
00293 std::vector<geom::LineString*> *nResultLineList,
00294 std::vector<geom::Polygon*> *nResultPolyList);
00295
00297 std::vector<geomgraph::Edge *>dupEdges;
00298
00303 int mergeZ(geomgraph::Node *n, const geom::Polygon *poly) const;
00304
00310 int mergeZ(geomgraph::Node *n, const geom::LineString *line) const;
00311
00315 double avgz[2];
00316 bool avgzcomputed[2];
00317
00318 double getAverageZ(int targetIndex);
00319 static double getAverageZ(const geom::Polygon *poly);
00320
00321 ElevationMatrix *elevationMatrix;
00322
00325 void checkObviouslyWrongResult(OpCode opCode);
00326
00327 };
00328
00332 struct overlayOp {
00333
00334 OverlayOp::OpCode opCode;
00335
00336 overlayOp(OverlayOp::OpCode code)
00337 :
00338 opCode(code)
00339 {}
00340
00341 geom::Geometry* operator() (const geom::Geometry* g0,
00342 const geom::Geometry* g1)
00343 {
00344 return OverlayOp::overlayOp(g0, g1, opCode);
00345 }
00346
00347 };
00348
00349 }
00350 }
00351 }
00352
00353 #endif // ndef GEOS_OP_OVERLAY_OVERLAYOP_H
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376