GEOS  3.9.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 
70 class GEOS_DLL OverlayOp: public GeometryGraphOperation {
71 
72 public:
73 
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 
122  static bool isResultOfOp(geom::Location loc0, geom::Location loc1, OpCode opCode);
123 
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 
191  static std::unique_ptr<geom::Geometry> createEmptyResult(
192  OverlayOp::OpCode overlayOpCode, const geom::Geometry* a,
193  const geom::Geometry* b, const geom::GeometryFactory* geomFact);
194 
195 protected:
196 
205  void insertUniqueEdge(geomgraph::Edge* e);
206 
207 private:
208 
209  algorithm::PointLocator ptLocator;
210 
211  const geom::GeometryFactory* geomFact;
212 
213  geom::Geometry* resultGeom;
214 
216 
217  geomgraph::EdgeList edgeList;
218 
219  std::vector<geom::Polygon*>* resultPolyList;
220 
221  std::vector<geom::LineString*>* resultLineList;
222 
223  std::vector<geom::Point*>* resultPointList;
224 
225  void computeOverlay(OpCode opCode); // throw(TopologyException *);
226 
227  void insertUniqueEdges(std::vector<geomgraph::Edge*>* edges, const geom::Envelope* env = nullptr);
228 
229  /*
230  * If either of the GeometryLocations for the existing label is
231  * exactly opposite to the one in the labelToMerge,
232  * this indicates a dimensional collapse has happened.
233  * In this case, convert the label for that Geometry to a Line label
234  */
235  //Not needed
236  //void checkDimensionalCollapse(geomgraph::Label labelToMerge, geomgraph::Label existingLabel);
237 
249  void computeLabelsFromDepths();
250 
255  void replaceCollapsedEdges();
256 
267  void copyPoints(int argIndex, const geom::Envelope* env = nullptr);
268 
277  void computeLabelling(); // throw(TopologyException *);
278 
286  void mergeSymLabels();
287 
288  void updateNodeLabelling();
289 
307  void labelIncompleteNodes();
308 
312  void labelIncompleteNode(geomgraph::Node* n, int targetIndex);
313 
325  void findResultAreaEdges(OpCode opCode);
326 
331  void cancelDuplicateResultEdges();
332 
337  bool isCovered(const geom::Coordinate& coord,
338  std::vector<geom::Geometry*>* geomList);
339 
344  bool isCovered(const geom::Coordinate& coord,
345  std::vector<geom::Polygon*>* geomList);
346 
351  bool isCovered(const geom::Coordinate& coord,
352  std::vector<geom::LineString*>* geomList);
357  static geom::Dimension::DimensionType resultDimension(OverlayOp::OpCode overlayOpCode,
358  const geom::Geometry* g0, const geom::Geometry* g1);
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 
403 } // namespace geos::operation::overlay
404 } // namespace geos::operation
405 } // namespace geos
406 
407 #ifdef _MSC_VER
408 #pragma warning(pop)
409 #endif
410 
411 #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
A EdgeList is a list of Edges.
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
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:68
Location
Constants representing the location of a point relative to a geometry.
Definition: Location.h:34
A Label indicates the topological relationship of a component of a topology graph to a given Geometry...
Definition: Label.h:59
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:26
The node component of a geometry graph.
Definition: geomgraph/Node.h:62
Definition: geomgraph/Edge.h:66
DimensionType
Definition: Dimension.h:31