00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef GEOS_OP_OVERLAY_OVERLAYOP_H
00017 #define GEOS_OP_OVERLAY_OVERLAYOP_H
00018
00019 #include <geos/operation/GeometryGraphOperation.h>
00020 #include <geos/geomgraph/EdgeList.h>
00021 #include <geos/algorithm/PointLocator.h>
00022 #include <geos/geomgraph/PlanarGraph.h>
00023
00024 #include <vector>
00025
00026
00027 namespace geos {
00028 namespace geom {
00029 class Geometry;
00030 class Coordinate;
00031 class GeometryFactory;
00032 class Polygon;
00033 class LineString;
00034 class Point;
00035 }
00036 namespace geomgraph {
00037 class Label;
00038 class Edge;
00039 class Node;
00040 }
00041 namespace operation {
00042 namespace overlay {
00043 class ElevationMatrix;
00044 }
00045 }
00046 }
00047
00048 namespace geos {
00049 namespace operation {
00050 namespace overlay {
00051
00053
00057 class OverlayOp: public GeometryGraphOperation {
00058
00059 public:
00060
00062
00066 enum OpCode {
00067 opINTERSECTION=1,
00068 opUNION,
00069 opDIFFERENCE,
00070 opSYMDIFFERENCE
00071 };
00072
00073 static geom::Geometry* overlayOp(const geom::Geometry *geom0,
00074 const geom::Geometry *geom1,
00075 OpCode opCode);
00076
00077
00078 static bool isResultOfOp(geomgraph::Label *label, OpCode opCode);
00079
00081
00084 static bool isResultOfOp(int loc0, int loc1, OpCode opCode);
00085
00087
00091 OverlayOp(const geom::Geometry *g0, const geom::Geometry *g1);
00092
00093 virtual ~OverlayOp();
00094
00095 geom::Geometry* getResultGeometry(OpCode funcCode);
00096
00097
00098 geomgraph::PlanarGraph& getGraph() { return graph; }
00099
00107 bool isCoveredByLA(const geom::Coordinate& coord);
00108
00115 bool isCoveredByA(const geom::Coordinate& coord);
00116
00117
00118
00119
00120
00121
00122 protected:
00123
00132 void insertUniqueEdge(geomgraph::Edge *e);
00133
00134 private:
00135
00136 algorithm::PointLocator ptLocator;
00137
00138 const geom::GeometryFactory *geomFact;
00139
00140 geom::Geometry *resultGeom;
00141
00142 geomgraph::PlanarGraph graph;
00143
00144 geomgraph::EdgeList edgeList;
00145
00146 std::vector<geom::Polygon*> *resultPolyList;
00147
00148 std::vector<geom::LineString*> *resultLineList;
00149
00150 std::vector<geom::Point*> *resultPointList;
00151
00152 void computeOverlay(OpCode opCode);
00153
00154 void insertUniqueEdges(std::vector<geomgraph::Edge*> *edges);
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00176 void computeLabelsFromDepths();
00177
00182 void replaceCollapsedEdges();
00183
00194 void copyPoints(int argIndex);
00195
00204 void computeLabelling();
00205
00213 void mergeSymLabels();
00214
00215 void updateNodeLabelling();
00216
00234 void labelIncompleteNodes();
00235
00239 void labelIncompleteNode(geomgraph::Node *n, int targetIndex);
00240
00252 void findResultAreaEdges(OpCode opCode);
00253
00258 void cancelDuplicateResultEdges();
00259
00264 bool isCovered(const geom::Coordinate& coord,
00265 std::vector<geom::Geometry*> *geomList);
00266
00271 bool isCovered(const geom::Coordinate& coord,
00272 std::vector<geom::Polygon*> *geomList);
00273
00278 bool isCovered(const geom::Coordinate& coord,
00279 std::vector<geom::LineString*> *geomList);
00280
00285 geom::Geometry* computeGeometry(
00286 std::vector<geom::Point*> *nResultPointList,
00287 std::vector<geom::LineString*> *nResultLineList,
00288 std::vector<geom::Polygon*> *nResultPolyList);
00289
00291 std::vector<geomgraph::Edge *>dupEdges;
00292
00297 int mergeZ(geomgraph::Node *n, const geom::Polygon *poly) const;
00298
00304 int mergeZ(geomgraph::Node *n, const geom::LineString *line) const;
00305
00309 double avgz[2];
00310 bool avgzcomputed[2];
00311
00312 double getAverageZ(int targetIndex);
00313 static double getAverageZ(const geom::Polygon *poly);
00314
00315 ElevationMatrix *elevationMatrix;
00316
00319 void checkObviouslyWrongResult(OpCode opCode);
00320
00321 };
00322
00326 struct overlayOp {
00327
00328 OverlayOp::OpCode opCode;
00329
00330 overlayOp(OverlayOp::OpCode code)
00331 :
00332 opCode(code)
00333 {}
00334
00335 geom::Geometry* operator() (const geom::Geometry* g0,
00336 const geom::Geometry* g1)
00337 {
00338 return OverlayOp::overlayOp(g0, g1, opCode);
00339 }
00340
00341 };
00342
00343 }
00344 }
00345 }
00346
00347 #endif // ndef GEOS_OP_OVERLAY_OVERLAYOP_H
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370