GEOS  3.8.0dev
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/algorithm/PointLocator.h> // for composition
25 #include <geos/geom/Dimension.h> // for Dimension::DimensionType
26 #include <geos/geomgraph/EdgeList.h> // for composition
27 #include <geos/geomgraph/PlanarGraph.h> // for inline (GeometryGraph->PlanarGraph)
28 #include <geos/operation/GeometryGraphOperation.h> // for inheritance
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 Envelope;
43 class GeometryFactory;
44 class Polygon;
45 class LineString;
46 class Point;
47 }
48 namespace geomgraph {
49 class Label;
50 class Edge;
51 class Node;
52 }
53 namespace operation {
54 namespace overlay {
55 class ElevationMatrix;
56 }
57 }
58 }
59 
60 namespace geos {
61 namespace operation { // geos::operation
62 namespace overlay { // geos::operation::overlay
63 
65 //
69 class GEOS_DLL OverlayOp: public GeometryGraphOperation {
70 
71 public:
72 
74  //
78  enum OpCode {
80  opINTERSECTION = 1,
82  opUNION = 2,
84  opDIFFERENCE = 3,
86  opSYMDIFFERENCE = 4
87  };
88 
98  static geom::Geometry* overlayOp(const geom::Geometry* geom0,
99  const geom::Geometry* geom1,
100  OpCode opCode);
101  //throw(TopologyException *);
102 
115  static bool isResultOfOp(const geomgraph::Label& label, OpCode opCode);
116 
118  //
121  static bool isResultOfOp(int loc0, int loc1, OpCode opCode);
122 
124  //
128  OverlayOp(const geom::Geometry* g0, const geom::Geometry* g1);
129 
130  ~OverlayOp() override; // FIXME: virtual ?
131 
141  geom::Geometry* getResultGeometry(OpCode overlayOpCode);
142  // throw(TopologyException *);
143 
151  {
152  return graph;
153  }
154 
162  bool isCoveredByLA(const geom::Coordinate& coord);
163 
170  bool isCoveredByA(const geom::Coordinate& coord);
171 
172  /*
173  * @return true if the coord is located in the interior or boundary of
174  * a geometry in the list.
175  */
176 
177 protected:
178 
187  void insertUniqueEdge(geomgraph::Edge* e);
188 
189 private:
190 
191  algorithm::PointLocator ptLocator;
192 
193  const geom::GeometryFactory* geomFact;
194 
195  geom::Geometry* resultGeom;
196 
198 
199  geomgraph::EdgeList edgeList;
200 
201  std::vector<geom::Polygon*>* resultPolyList;
202 
203  std::vector<geom::LineString*>* resultLineList;
204 
205  std::vector<geom::Point*>* resultPointList;
206 
207  void computeOverlay(OpCode opCode); // throw(TopologyException *);
208 
209  void insertUniqueEdges(std::vector<geomgraph::Edge*>* edges, const geom::Envelope* env = nullptr);
210 
211  /*
212  * If either of the GeometryLocations for the existing label is
213  * exactly opposite to the one in the labelToMerge,
214  * this indicates a dimensional collapse has happened.
215  * In this case, convert the label for that Geometry to a Line label
216  */
217  //Not needed
218  //void checkDimensionalCollapse(geomgraph::Label labelToMerge, geomgraph::Label existingLabel);
219 
231  void computeLabelsFromDepths();
232 
237  void replaceCollapsedEdges();
238 
249  void copyPoints(int argIndex, const geom::Envelope* env = nullptr);
250 
259  void computeLabelling(); // throw(TopologyException *);
260 
268  void mergeSymLabels();
269 
270  void updateNodeLabelling();
271 
289  void labelIncompleteNodes();
290 
294  void labelIncompleteNode(geomgraph::Node* n, int targetIndex);
295 
307  void findResultAreaEdges(OpCode opCode);
308 
313  void cancelDuplicateResultEdges();
314 
319  bool isCovered(const geom::Coordinate& coord,
320  std::vector<geom::Geometry*>* geomList);
321 
326  bool isCovered(const geom::Coordinate& coord,
327  std::vector<geom::Polygon*>* geomList);
328 
333  bool isCovered(const geom::Coordinate& coord,
334  std::vector<geom::LineString*>* geomList);
339  static geom::Dimension::DimensionType resultDimension(OverlayOp::OpCode overlayOpCode,
340  const geom::Geometry* g0, const geom::Geometry* g1);
341 
355  static geom::Geometry* createEmptyResult(
356  OverlayOp::OpCode overlayOpCode, const geom::Geometry* a,
357  const geom::Geometry* b, const geom::GeometryFactory* geomFact);
358 
363  geom::Geometry* computeGeometry(
364  std::vector<geom::Point*>* nResultPointList,
365  std::vector<geom::LineString*>* nResultLineList,
366  std::vector<geom::Polygon*>* nResultPolyList,
367  OverlayOp::OpCode opCode);
368 
370  std::vector<geomgraph::Edge*>dupEdges;
371 
376  int mergeZ(geomgraph::Node* n, const geom::Polygon* poly) const;
377 
383  int mergeZ(geomgraph::Node* n, const geom::LineString* line) const;
384 
388  double avgz[2];
389  bool avgzcomputed[2];
390 
391  double getAverageZ(int targetIndex);
392  static double getAverageZ(const geom::Polygon* poly);
393 
394  ElevationMatrix* elevationMatrix;
395 
398  void checkObviouslyWrongResult(OpCode opCode);
399 
400 };
401 
405 struct overlayOp {
406 
407  OverlayOp::OpCode opCode;
408 
410  :
411  opCode(code)
412  {}
413 
415  operator()(const geom::Geometry* g0,
416  const geom::Geometry* g1)
417  {
418  return OverlayOp::overlayOp(g0, g1, opCode);
419  }
420 
421 };
422 
423 } // namespace geos::operation::overlay
424 } // namespace geos::operation
425 } // namespace geos
426 
427 #ifdef _MSC_VER
428 #pragma warning(pop)
429 #endif
430 
431 #endif // ndef GEOS_OP_OVERLAY_OVERLAYOP_H
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:59
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
geomgraph::PlanarGraph & getGraph()
Definition: OverlayOp.h:150
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:78
Definition: EdgeList.h:58
Computes the geometric overlay of two Geometry.
Definition: OverlayOp.h:69
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:187
static geom::Geometry * overlayOp(const geom::Geometry *geom0, const geom::Geometry *geom1, OpCode opCode)
Definition: LineString.h:69
The base class for operations that require GeometryGraph.
Definition: GeometryGraphOperation.h:52
Represents a linear polygon, which may include holes.
Definition: Polygon.h:65
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:405
A Label indicates the topological relationship of a component of a topology graph to a given Geometry...
Definition: Label.h:57
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25
Definition: geomgraph/Node.h:62
Definition: geomgraph/Edge.h:66
DimensionType
Definition: Dimension.h:31