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 #ifdef _MSC_VER
00033 #pragma warning(push)
00034 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
00035 #endif
00036
00037
00038 namespace geos {
00039 namespace geom {
00040 class Geometry;
00041 class Coordinate;
00042 class GeometryFactory;
00043 class Polygon;
00044 class LineString;
00045 class Point;
00046 }
00047 namespace geomgraph {
00048 class Label;
00049 class Edge;
00050 class Node;
00051 }
00052 namespace operation {
00053 namespace overlay {
00054 class ElevationMatrix;
00055 }
00056 }
00057 }
00058
00059 namespace geos {
00060 namespace operation {
00061 namespace overlay {
00062
00064
00068 class GEOS_DLL OverlayOp: public GeometryGraphOperation {
00069
00070 public:
00071
00073
00077 enum OpCode {
00078 opINTERSECTION=1,
00079 opUNION,
00080 opDIFFERENCE,
00081 opSYMDIFFERENCE
00082 };
00083
00084 static geom::Geometry* overlayOp(const geom::Geometry *geom0,
00085 const geom::Geometry *geom1,
00086 OpCode opCode);
00087
00088
00089 static bool isResultOfOp(geomgraph::Label *label, OpCode opCode);
00090
00092
00095 static bool isResultOfOp(int loc0, int loc1, OpCode opCode);
00096
00098
00102 OverlayOp(const geom::Geometry *g0, const geom::Geometry *g1);
00103
00104 virtual ~OverlayOp();
00105
00106 geom::Geometry* getResultGeometry(OpCode funcCode);
00107
00108
00109 geomgraph::PlanarGraph& getGraph() { return graph; }
00110
00118 bool isCoveredByLA(const geom::Coordinate& coord);
00119
00126 bool isCoveredByA(const geom::Coordinate& coord);
00127
00128
00129
00130
00131
00132
00133 protected:
00134
00143 void insertUniqueEdge(geomgraph::Edge *e);
00144
00145 private:
00146
00147 algorithm::PointLocator ptLocator;
00148
00149 const geom::GeometryFactory *geomFact;
00150
00151 geom::Geometry *resultGeom;
00152
00153 geomgraph::PlanarGraph graph;
00154
00155 geomgraph::EdgeList edgeList;
00156
00157 std::vector<geom::Polygon*> *resultPolyList;
00158
00159 std::vector<geom::LineString*> *resultLineList;
00160
00161 std::vector<geom::Point*> *resultPointList;
00162
00163 void computeOverlay(OpCode opCode);
00164
00165 void insertUniqueEdges(std::vector<geomgraph::Edge*> *edges);
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00187 void computeLabelsFromDepths();
00188
00193 void replaceCollapsedEdges();
00194
00205 void copyPoints(int argIndex);
00206
00215 void computeLabelling();
00216
00224 void mergeSymLabels();
00225
00226 void updateNodeLabelling();
00227
00245 void labelIncompleteNodes();
00246
00250 void labelIncompleteNode(geomgraph::Node *n, int targetIndex);
00251
00263 void findResultAreaEdges(OpCode opCode);
00264
00269 void cancelDuplicateResultEdges();
00270
00275 bool isCovered(const geom::Coordinate& coord,
00276 std::vector<geom::Geometry*> *geomList);
00277
00282 bool isCovered(const geom::Coordinate& coord,
00283 std::vector<geom::Polygon*> *geomList);
00284
00289 bool isCovered(const geom::Coordinate& coord,
00290 std::vector<geom::LineString*> *geomList);
00291
00296 geom::Geometry* computeGeometry(
00297 std::vector<geom::Point*> *nResultPointList,
00298 std::vector<geom::LineString*> *nResultLineList,
00299 std::vector<geom::Polygon*> *nResultPolyList);
00300
00302 std::vector<geomgraph::Edge *>dupEdges;
00303
00308 int mergeZ(geomgraph::Node *n, const geom::Polygon *poly) const;
00309
00315 int mergeZ(geomgraph::Node *n, const geom::LineString *line) const;
00316
00320 double avgz[2];
00321 bool avgzcomputed[2];
00322
00323 double getAverageZ(int targetIndex);
00324 static double getAverageZ(const geom::Polygon *poly);
00325
00326 ElevationMatrix *elevationMatrix;
00327
00330 void checkObviouslyWrongResult(OpCode opCode);
00331
00332 };
00333
00337 struct overlayOp {
00338
00339 OverlayOp::OpCode opCode;
00340
00341 overlayOp(OverlayOp::OpCode code)
00342 :
00343 opCode(code)
00344 {}
00345
00346 geom::Geometry* operator() (const geom::Geometry* g0,
00347 const geom::Geometry* g1)
00348 {
00349 return OverlayOp::overlayOp(g0, g1, opCode);
00350 }
00351
00352 };
00353
00354 }
00355 }
00356 }
00357
00358 #ifdef _MSC_VER
00359 #pragma warning(pop)
00360 #endif
00361
00362 #endif // ndef GEOS_OP_OVERLAY_OVERLAYOP_H
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385