GEOS  3.4.2
OverlayOp.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2006 Refractions Research Inc.
7  *
8  * This is free software; you can redistribute and/or modify it under
9  * the terms of the GNU Lesser General Public Licence as published
10  * by the Free Software Foundation.
11  * See the COPYING file for more information.
12  *
13  ***********************************************************************
14  *
15  * Last port: operation/overlay/OverlayOp.java r567 (JTS-1.12+)
16  *
17  **********************************************************************/
18 
19 #ifndef GEOS_OP_OVERLAY_OVERLAYOP_H
20 #define GEOS_OP_OVERLAY_OVERLAYOP_H
21 
22 #include <geos/export.h>
23 
24 #include <geos/operation/GeometryGraphOperation.h> // for inheritance
25 #include <geos/geomgraph/EdgeList.h> // for composition
26 #include <geos/algorithm/PointLocator.h> // for composition
27 #include <geos/geomgraph/PlanarGraph.h> // for inline (GeometryGraph->PlanarGraph)
28 
29 #include <vector>
30 
31 #ifdef _MSC_VER
32 #pragma warning(push)
33 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
34 #endif
35 
36 // Forward declarations
37 namespace geos {
38  namespace geom {
39  class Geometry;
40  class Coordinate;
41  class GeometryFactory;
42  class Polygon;
43  class LineString;
44  class Point;
45  }
46  namespace geomgraph {
47  class Label;
48  class Edge;
49  class Node;
50  }
51  namespace operation {
52  namespace overlay {
53  class ElevationMatrix;
54  }
55  }
56 }
57 
58 namespace geos {
59 namespace operation { // geos::operation
60 namespace overlay { // geos::operation::overlay
61 
63 //
67 class GEOS_DLL OverlayOp: public GeometryGraphOperation {
68 
69 public:
70 
72  //
76  enum OpCode {
78  opINTERSECTION = 1,
80  opUNION = 2,
82  opDIFFERENCE = 3,
84  opSYMDIFFERENCE = 4
85  };
86 
96  static geom::Geometry* overlayOp(const geom::Geometry *geom0,
97  const geom::Geometry *geom1,
98  OpCode opCode);
99  //throw(TopologyException *);
100 
113  static bool isResultOfOp(const geomgraph::Label& label, OpCode opCode);
114 
116  //
119  static bool isResultOfOp(int loc0, int loc1, OpCode opCode);
120 
122  //
126  OverlayOp(const geom::Geometry *g0, const geom::Geometry *g1);
127 
128  virtual ~OverlayOp(); // FIXME: virtual ?
129 
139  geom::Geometry* getResultGeometry(OpCode overlayOpCode);
140  // throw(TopologyException *);
141 
147  geomgraph::PlanarGraph& getGraph() { return graph; }
148 
156  bool isCoveredByLA(const geom::Coordinate& coord);
157 
164  bool isCoveredByA(const geom::Coordinate& coord);
165 
166  /*
167  * @return true if the coord is located in the interior or boundary of
168  * a geometry in the list.
169  */
170 
171 protected:
172 
181  void insertUniqueEdge(geomgraph::Edge *e);
182 
183 private:
184 
185  algorithm::PointLocator ptLocator;
186 
187  const geom::GeometryFactory *geomFact;
188 
189  geom::Geometry *resultGeom;
190 
192 
193  geomgraph::EdgeList edgeList;
194 
195  std::vector<geom::Polygon*> *resultPolyList;
196 
197  std::vector<geom::LineString*> *resultLineList;
198 
199  std::vector<geom::Point*> *resultPointList;
200 
201  void computeOverlay(OpCode opCode); // throw(TopologyException *);
202 
203  void insertUniqueEdges(std::vector<geomgraph::Edge*> *edges);
204 
205  /*
206  * If either of the GeometryLocations for the existing label is
207  * exactly opposite to the one in the labelToMerge,
208  * this indicates a dimensional collapse has happened.
209  * In this case, convert the label for that Geometry to a Line label
210  */
211  //Not needed
212  //void checkDimensionalCollapse(geomgraph::Label labelToMerge, geomgraph::Label existingLabel);
213 
225  void computeLabelsFromDepths();
226 
231  void replaceCollapsedEdges();
232 
243  void copyPoints(int argIndex);
244 
253  void computeLabelling(); // throw(TopologyException *);
254 
262  void mergeSymLabels();
263 
264  void updateNodeLabelling();
265 
283  void labelIncompleteNodes();
284 
288  void labelIncompleteNode(geomgraph::Node *n, int targetIndex);
289 
301  void findResultAreaEdges(OpCode opCode);
302 
307  void cancelDuplicateResultEdges();
308 
313  bool isCovered(const geom::Coordinate& coord,
314  std::vector<geom::Geometry*> *geomList);
315 
320  bool isCovered(const geom::Coordinate& coord,
321  std::vector<geom::Polygon*> *geomList);
322 
327  bool isCovered(const geom::Coordinate& coord,
328  std::vector<geom::LineString*> *geomList);
329 
334  geom::Geometry* computeGeometry(
335  std::vector<geom::Point*> *nResultPointList,
336  std::vector<geom::LineString*> *nResultLineList,
337  std::vector<geom::Polygon*> *nResultPolyList);
338 
340  std::vector<geomgraph::Edge *>dupEdges;
341 
346  int mergeZ(geomgraph::Node *n, const geom::Polygon *poly) const;
347 
353  int mergeZ(geomgraph::Node *n, const geom::LineString *line) const;
354 
358  double avgz[2];
359  bool avgzcomputed[2];
360 
361  double getAverageZ(int targetIndex);
362  static double getAverageZ(const geom::Polygon *poly);
363 
364  ElevationMatrix *elevationMatrix;
365 
368  void checkObviouslyWrongResult(OpCode opCode);
369 
370 };
371 
375 struct overlayOp {
376 
377  OverlayOp::OpCode opCode;
378 
380  :
381  opCode(code)
382  {}
383 
384  geom::Geometry* operator() (const geom::Geometry* g0,
385  const geom::Geometry* g1)
386  {
387  return OverlayOp::overlayOp(g0, g1, opCode);
388  }
389 
390 };
391 
392 } // namespace geos::operation::overlay
393 } // namespace geos::operation
394 } // namespace geos
395 
396 #ifdef _MSC_VER
397 #pragma warning(pop)
398 #endif
399 
400 #endif // ndef GEOS_OP_OVERLAY_OVERLAYOP_H
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
geomgraph::PlanarGraph & getGraph()
Definition: OverlayOp.h:147
Represents a directed graph which is embeddable in a planar surface.
Definition: geomgraph/PlanarGraph.h:75
OpCode
The spatial functions supported by this class.
Definition: OverlayOp.h:76
Definition: EdgeList.h:58
Computes the geometric overlay of two Geometry.
Definition: OverlayOp.h:67
Computes the topological relationship (Location) of a single point to a Geometry. ...
Definition: PointLocator.h:57
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:167
static geom::Geometry * overlayOp(const geom::Geometry *geom0, const geom::Geometry *geom1, OpCode opCode)
Definition: LineString.h:70
The base class for operations that require GeometryGraph.
Definition: GeometryGraphOperation.h:52
Represents a linear polygon, which may include holes.
Definition: Polygon.h:66
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:67
OverlayOp::overlayOp Adapter for use with geom::BinaryOp.
Definition: OverlayOp.h:375
A Label indicates the topological relationship of a component of a topology graph to a given Geometry...
Definition: Label.h:57
Definition: geomgraph/Node.h:62
Definition: geomgraph/Edge.h:66