00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef GEOS_OP_OVERLAY_OVERLAYOP_H
00020 #define GEOS_OP_OVERLAY_OVERLAYOP_H
00021
00022 #include <geos/export.h>
00023
00024 #include <geos/operation/GeometryGraphOperation.h>
00025 #include <geos/geomgraph/EdgeList.h>
00026 #include <geos/algorithm/PointLocator.h>
00027 #include <geos/geomgraph/PlanarGraph.h>
00028
00029 #include <vector>
00030
00031 #ifdef _MSC_VER
00032 #pragma warning(push)
00033 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
00034 #endif
00035
00036
00037 namespace geos {
00038 namespace geom {
00039 class Geometry;
00040 class Coordinate;
00041 class GeometryFactory;
00042 class Polygon;
00043 class LineString;
00044 class Point;
00045 }
00046 namespace geomgraph {
00047 class Label;
00048 class Edge;
00049 class Node;
00050 }
00051 namespace operation {
00052 namespace overlay {
00053 class ElevationMatrix;
00054 }
00055 }
00056 }
00057
00058 namespace geos {
00059 namespace operation {
00060 namespace overlay {
00061
00063
00067 class GEOS_DLL OverlayOp: public GeometryGraphOperation {
00068
00069 public:
00070
00072
00076 enum OpCode {
00078 opINTERSECTION = 1,
00080 opUNION = 2,
00082 opDIFFERENCE = 3,
00084 opSYMDIFFERENCE = 4
00085 };
00086
00096 static geom::Geometry* overlayOp(const geom::Geometry *geom0,
00097 const geom::Geometry *geom1,
00098 OpCode opCode);
00099
00100
00113 static bool isResultOfOp(const geomgraph::Label& label, OpCode opCode);
00114
00116
00119 static bool isResultOfOp(int loc0, int loc1, OpCode opCode);
00120
00122
00126 OverlayOp(const geom::Geometry *g0, const geom::Geometry *g1);
00127
00128 virtual ~OverlayOp();
00129
00139 geom::Geometry* getResultGeometry(OpCode overlayOpCode);
00140
00141
00147 geomgraph::PlanarGraph& getGraph() { return graph; }
00148
00156 bool isCoveredByLA(const geom::Coordinate& coord);
00157
00164 bool isCoveredByA(const geom::Coordinate& coord);
00165
00166
00167
00168
00169
00170
00171 protected:
00172
00181 void insertUniqueEdge(geomgraph::Edge *e);
00182
00183 private:
00184
00185 algorithm::PointLocator ptLocator;
00186
00187 const geom::GeometryFactory *geomFact;
00188
00189 geom::Geometry *resultGeom;
00190
00191 geomgraph::PlanarGraph graph;
00192
00193 geomgraph::EdgeList edgeList;
00194
00195 std::vector<geom::Polygon*> *resultPolyList;
00196
00197 std::vector<geom::LineString*> *resultLineList;
00198
00199 std::vector<geom::Point*> *resultPointList;
00200
00201 void computeOverlay(OpCode opCode);
00202
00203 void insertUniqueEdges(std::vector<geomgraph::Edge*> *edges);
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00225 void computeLabelsFromDepths();
00226
00231 void replaceCollapsedEdges();
00232
00243 void copyPoints(int argIndex);
00244
00253 void computeLabelling();
00254
00262 void mergeSymLabels();
00263
00264 void updateNodeLabelling();
00265
00283 void labelIncompleteNodes();
00284
00288 void labelIncompleteNode(geomgraph::Node *n, int targetIndex);
00289
00301 void findResultAreaEdges(OpCode opCode);
00302
00307 void cancelDuplicateResultEdges();
00308
00313 bool isCovered(const geom::Coordinate& coord,
00314 std::vector<geom::Geometry*> *geomList);
00315
00320 bool isCovered(const geom::Coordinate& coord,
00321 std::vector<geom::Polygon*> *geomList);
00322
00327 bool isCovered(const geom::Coordinate& coord,
00328 std::vector<geom::LineString*> *geomList);
00329
00334 geom::Geometry* computeGeometry(
00335 std::vector<geom::Point*> *nResultPointList,
00336 std::vector<geom::LineString*> *nResultLineList,
00337 std::vector<geom::Polygon*> *nResultPolyList);
00338
00340 std::vector<geomgraph::Edge *>dupEdges;
00341
00346 int mergeZ(geomgraph::Node *n, const geom::Polygon *poly) const;
00347
00353 int mergeZ(geomgraph::Node *n, const geom::LineString *line) const;
00354
00358 double avgz[2];
00359 bool avgzcomputed[2];
00360
00361 double getAverageZ(int targetIndex);
00362 static double getAverageZ(const geom::Polygon *poly);
00363
00364 ElevationMatrix *elevationMatrix;
00365
00368 void checkObviouslyWrongResult(OpCode opCode);
00369
00370 };
00371
00375 struct overlayOp {
00376
00377 OverlayOp::OpCode opCode;
00378
00379 overlayOp(OverlayOp::OpCode code)
00380 :
00381 opCode(code)
00382 {}
00383
00384 geom::Geometry* operator() (const geom::Geometry* g0,
00385 const geom::Geometry* g1)
00386 {
00387 return OverlayOp::overlayOp(g0, g1, opCode);
00388 }
00389
00390 };
00391
00392 }
00393 }
00394 }
00395
00396 #ifdef _MSC_VER
00397 #pragma warning(pop)
00398 #endif
00399
00400 #endif // ndef GEOS_OP_OVERLAY_OVERLAYOP_H