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/geom/Location.h>
27 #include <geos/geomgraph/EdgeList.h> // for composition
28 #include <geos/geomgraph/PlanarGraph.h> // for inline (GeometryGraph->PlanarGraph)
29 #include <geos/operation/GeometryGraphOperation.h> // for inheritance
30 
31 #include <vector>
32 
33 #ifdef _MSC_VER
34 #pragma warning(push)
35 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
36 #endif
37 
38 // Forward declarations
39 namespace geos {
40 namespace geom {
41 class Geometry;
42 class Coordinate;
43 class Envelope;
44 class GeometryFactory;
45 class Polygon;
46 class LineString;
47 class Point;
48 }
49 namespace geomgraph {
50 class Label;
51 class Edge;
52 class Node;
53 }
54 namespace operation {
55 namespace overlay {
56 class ElevationMatrix;
57 }
58 }
59 }
60 
61 namespace geos {
62 namespace operation { // geos::operation
63 namespace overlay { // geos::operation::overlay
64 
66 //
70 class GEOS_DLL OverlayOp: public GeometryGraphOperation {
71 
72 public:
73 
75  //
79  enum OpCode {
81  opINTERSECTION = 1,
83  opUNION = 2,
85  opDIFFERENCE = 3,
87  opSYMDIFFERENCE = 4
88  };
89 
99  static geom::Geometry* overlayOp(const geom::Geometry* geom0,
100  const geom::Geometry* geom1,
101  OpCode opCode);
102  //throw(TopologyException *);
103 
116  static bool isResultOfOp(const geomgraph::Label& label, OpCode opCode);
117 
119  //
122  static bool isResultOfOp(geom::Location loc0, geom::Location loc1, OpCode opCode);
123 
125  //
129  OverlayOp(const geom::Geometry* g0, const geom::Geometry* g1);
130 
131  ~OverlayOp() override; // FIXME: virtual ?
132 
142  geom::Geometry* getResultGeometry(OpCode overlayOpCode);
143  // throw(TopologyException *);
144 
152  {
153  return graph;
154  }
155 
163  bool isCoveredByLA(const geom::Coordinate& coord);
164 
171  bool isCoveredByA(const geom::Coordinate& coord);
172 
173  /*
174  * @return true if the coord is located in the interior or boundary of
175  * a geometry in the list.
176  */
177 
178 protected:
179 
188  void insertUniqueEdge(geomgraph::Edge* e);
189 
190 private:
191 
192  algorithm::PointLocator ptLocator;
193 
194  const geom::GeometryFactory* geomFact;
195 
196  geom::Geometry* resultGeom;
197 
199 
200  geomgraph::EdgeList edgeList;
201 
202  std::vector<geom::Polygon*>* resultPolyList;
203 
204  std::vector<geom::LineString*>* resultLineList;
205 
206  std::vector<geom::Point*>* resultPointList;
207 
208  void computeOverlay(OpCode opCode); // throw(TopologyException *);
209 
210  void insertUniqueEdges(std::vector<geomgraph::Edge*>* edges, const geom::Envelope* env = nullptr);
211 
212  /*
213  * If either of the GeometryLocations for the existing label is
214  * exactly opposite to the one in the labelToMerge,
215  * this indicates a dimensional collapse has happened.
216  * In this case, convert the label for that Geometry to a Line label
217  */
218  //Not needed
219  //void checkDimensionalCollapse(geomgraph::Label labelToMerge, geomgraph::Label existingLabel);
220 
232  void computeLabelsFromDepths();
233 
238  void replaceCollapsedEdges();
239 
250  void copyPoints(int argIndex, const geom::Envelope* env = nullptr);
251 
260  void computeLabelling(); // throw(TopologyException *);
261 
269  void mergeSymLabels();
270 
271  void updateNodeLabelling();
272 
290  void labelIncompleteNodes();
291 
295  void labelIncompleteNode(geomgraph::Node* n, int targetIndex);
296 
308  void findResultAreaEdges(OpCode opCode);
309 
314  void cancelDuplicateResultEdges();
315 
320  bool isCovered(const geom::Coordinate& coord,
321  std::vector<geom::Geometry*>* geomList);
322 
327  bool isCovered(const geom::Coordinate& coord,
328  std::vector<geom::Polygon*>* geomList);
329 
334  bool isCovered(const geom::Coordinate& coord,
335  std::vector<geom::LineString*>* geomList);
340  static geom::Dimension::DimensionType resultDimension(OverlayOp::OpCode overlayOpCode,
341  const geom::Geometry* g0, const geom::Geometry* g1);
342 
356  static geom::Geometry* createEmptyResult(
357  OverlayOp::OpCode overlayOpCode, const geom::Geometry* a,
358  const geom::Geometry* b, const geom::GeometryFactory* geomFact);
359 
364  geom::Geometry* computeGeometry(
365  std::vector<geom::Point*>* nResultPointList,
366  std::vector<geom::LineString*>* nResultLineList,
367  std::vector<geom::Polygon*>* nResultPolyList,
368  OverlayOp::OpCode opCode);
369 
371  std::vector<geomgraph::Edge*>dupEdges;
372 
377  int mergeZ(geomgraph::Node* n, const geom::Polygon* poly) const;
378 
384  int mergeZ(geomgraph::Node* n, const geom::LineString* line) const;
385 
389  double avgz[2];
390  bool avgzcomputed[2];
391 
392  double getAverageZ(int targetIndex);
393  static double getAverageZ(const geom::Polygon* poly);
394 
395  ElevationMatrix* elevationMatrix;
396 
399  void checkObviouslyWrongResult(OpCode opCode);
400 
401 };
402 
406 struct overlayOp {
407 
408  OverlayOp::OpCode opCode;
409 
411  :
412  opCode(code)
413  {}
414 
416  operator()(const geom::Geometry* g0,
417  const geom::Geometry* g1)
418  {
419  return OverlayOp::overlayOp(g0, g1, opCode);
420  }
421 
422 };
423 
424 } // namespace geos::operation::overlay
425 } // namespace geos::operation
426 } // namespace geos
427 
428 #ifdef _MSC_VER
429 #pragma warning(pop)
430 #endif
431 
432 #endif // ndef GEOS_OP_OVERLAY_OVERLAYOP_H
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:58
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
geomgraph::PlanarGraph & getGraph()
Gets the graph constructed to compute the overlay.
Definition: OverlayOp.h:151
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:79
Definition: EdgeList.h:58
Computes the geometric overlay of two Geometry.
Definition: OverlayOp.h:70
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:188
static geom::Geometry * overlayOp(const geom::Geometry *geom0, const geom::Geometry *geom1, OpCode opCode)
Computes an overlay operation for the given geometry arguments.
Definition: LineString.h:68
The base class for operations that require GeometryGraph.
Definition: GeometryGraphOperation.h:52
Represents a linear polygon, which may include holes.
Definition: Polygon.h:64
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:66
Location
Constants representing the location of a point relative to a geometry.
Definition: Location.h:33
OverlayOp::overlayOp Adapter for use with geom::BinaryOp.
Definition: OverlayOp.h:406
A Label indicates the topological relationship of a component of a topology graph to a given Geometry...
Definition: Label.h:58
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