GEOS 3.3.4

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List

OverlayOp.h
1 /**********************************************************************
2 * $Id: OverlayOp.h 3551 2011-12-15 11:35:28Z strk $
3 *
4 * GEOS - Geometry Engine Open Source
5 * http://geos.refractions.net
6 *
7 * Copyright (C) 2006 Refractions Research Inc.
8 *
9 * This is free software; you can redistribute and/or modify it under
10 * the terms of the GNU Lesser General Public Licence as published
11 * by the Free Software Foundation.
12 * See the COPYING file for more information.
13 *
14 ***********************************************************************
15 *
16 * Last port: operation/overlay/OverlayOp.java rev. 1.31 (JTS-1.10)
17 *
18 **********************************************************************/
19
20 #ifndef GEOS_OP_OVERLAY_OVERLAYOP_H
21 #define GEOS_OP_OVERLAY_OVERLAYOP_H
22
23 #include <geos/export.h>
24
25 #include <geos/operation/GeometryGraphOperation.h> // for inheritance
26 #include <geos/geomgraph/EdgeList.h> // for composition
27 #include <geos/algorithm/PointLocator.h> // for composition
28 #include <geos/geomgraph/PlanarGraph.h> // for inline (GeometryGraph->PlanarGraph)
29
30 #include <vector>
31
32 #ifdef _MSC_VER
33 #pragma warning(push)
34 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
35 #endif
36
37 // Forward declarations
38 namespace geos {
39 namespace geom {
40 class Geometry;
41 class Coordinate;
42 class GeometryFactory;
43 class Polygon;
44 class LineString;
45 class Point;
46 }
47 namespace geomgraph {
48 class Label;
49 class Edge;
50 class Node;
51 }
52 namespace operation {
53 namespace overlay {
54 class ElevationMatrix;
55 }
56 }
57 }
58
59 namespace geos {
60 namespace operation { // geos::operation
61 namespace overlay { // geos::operation::overlay
62
64 //
68 class GEOS_DLL OverlayOp: public GeometryGraphOperation {
69
70 public:
71
73 //
77 enum OpCode {
78 opINTERSECTION=1,
79 opUNION,
80 opDIFFERENCE,
81 opSYMDIFFERENCE
82 };
83
84 static geom::Geometry* overlayOp(const geom::Geometry *geom0,
85 const geom::Geometry *geom1,
86 OpCode opCode);
87 //throw(TopologyException *);
88
89 static bool isResultOfOp(geomgraph::Label *label, OpCode opCode);
90
92 //
95 static bool isResultOfOp(int loc0, int loc1, OpCode opCode);
96
98 //
102 OverlayOp(const geom::Geometry *g0, const geom::Geometry *g1);
103
104 virtual ~OverlayOp(); // FIXME: virtual ?
105
106 geom::Geometry* getResultGeometry(OpCode funcCode);
107 // throw(TopologyException *);
108
109 geomgraph::PlanarGraph& getGraph() { return graph; }
110
118 bool isCoveredByLA(const geom::Coordinate& coord);
119
126 bool isCoveredByA(const geom::Coordinate& coord);
127
128 /*
129 * @return true if the coord is located in the interior or boundary of
130 * a geometry in the list.
131 */
132
133 protected:
134
143 void insertUniqueEdge(geomgraph::Edge *e);
144
145 private:
146
147 algorithm::PointLocator ptLocator;
148
149 const geom::GeometryFactory *geomFact;
150
151 geom::Geometry *resultGeom;
152
153 geomgraph::PlanarGraph graph;
154
155 geomgraph::EdgeList edgeList;
156
157 std::vector<geom::Polygon*> *resultPolyList;
158
159 std::vector<geom::LineString*> *resultLineList;
160
161 std::vector<geom::Point*> *resultPointList;
162
163 void computeOverlay(OpCode opCode); // throw(TopologyException *);
164
165 void insertUniqueEdges(std::vector<geomgraph::Edge*> *edges);
166
167 /*
168 * If either of the GeometryLocations for the existing label is
169 * exactly opposite to the one in the labelToMerge,
170 * this indicates a dimensional collapse has happened.
171 * In this case, convert the label for that Geometry to a Line label
172 */
173 //Not needed
174 //void checkDimensionalCollapse(geomgraph::Label labelToMerge, geomgraph::Label existingLabel);
175
187 void computeLabelsFromDepths();
188
193 void replaceCollapsedEdges();
194
205 void copyPoints(int argIndex);
206
215 void computeLabelling(); // throw(TopologyException *);
216
224 void mergeSymLabels();
225
226 void updateNodeLabelling();
227
245 void labelIncompleteNodes();
246
250 void labelIncompleteNode(geomgraph::Node *n, int targetIndex);
251
263 void findResultAreaEdges(OpCode opCode);
264
269 void cancelDuplicateResultEdges();
270
275 bool isCovered(const geom::Coordinate& coord,
276 std::vector<geom::Geometry*> *geomList);
277
282 bool isCovered(const geom::Coordinate& coord,
283 std::vector<geom::Polygon*> *geomList);
284
289 bool isCovered(const geom::Coordinate& coord,
290 std::vector<geom::LineString*> *geomList);
291
296 geom::Geometry* computeGeometry(
297 std::vector<geom::Point*> *nResultPointList,
298 std::vector<geom::LineString*> *nResultLineList,
299 std::vector<geom::Polygon*> *nResultPolyList);
300
302 std::vector<geomgraph::Edge *>dupEdges;
303
308 int mergeZ(geomgraph::Node *n, const geom::Polygon *poly) const;
309
315 int mergeZ(geomgraph::Node *n, const geom::LineString *line) const;
316
320 double avgz[2];
321 bool avgzcomputed[2];
322
323 double getAverageZ(int targetIndex);
324 static double getAverageZ(const geom::Polygon *poly);
325
326 ElevationMatrix *elevationMatrix;
327
330 void checkObviouslyWrongResult(OpCode opCode);
331
332 };
333
337 struct overlayOp {
338
339 OverlayOp::OpCode opCode;
340
341 overlayOp(OverlayOp::OpCode code)
342 :
343 opCode(code)
344 {}
345
346 geom::Geometry* operator() (const geom::Geometry* g0,
347 const geom::Geometry* g1)
348 {
349 return OverlayOp::overlayOp(g0, g1, opCode);
350 }
351
352 };
353
354 } // namespace geos::operation::overlay
355 } // namespace geos::operation
356 } // namespace geos
357
358 #ifdef _MSC_VER
359 #pragma warning(pop)
360 #endif
361
362 #endif // ndef GEOS_OP_OVERLAY_OVERLAYOP_H
363
364 /**********************************************************************
365 * $Log$
366 * Revision 1.6 2006/07/05 20:19:29 strk
367 * added checks for obviously wrong result of difference and intersection ops
368 *
369 * Revision 1.5 2006/06/05 15:36:34 strk
370 * Given OverlayOp funx code enum a name and renamed values to have a lowercase prefix. Drop all of noding headers from installed header set.
371 *
372 * Revision 1.4 2006/05/24 15:17:44 strk
373 * Reduced number of installed headers in geos/operation/ subdir
374 *
375 * Revision 1.3 2006/04/14 15:04:36 strk
376 * fixed missing namespace qualification in overlay::overlayOp
377 *
378 * Revision 1.2 2006/04/14 14:35:47 strk
379 * Added overlayOp() adapter for use in templates expecting binary ops
380 *
381 * Revision 1.1 2006/03/17 13:24:59 strk
382 * opOverlay.h header splitted. Reduced header inclusions in operation/overlay implementation files. ElevationMatrixFilter code moved from own file to ElevationMatrix.cpp (ideally a class-private).
383 *
384 **********************************************************************/
385