GEOS 3.11.1
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#pragma once
20
21#include <geos/export.h>
22
23#include <geos/algorithm/PointLocator.h> // for composition
24#include <geos/geom/Dimension.h> // for Dimension::DimensionType
25#include <geos/geom/Location.h>
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
38namespace geos {
39namespace geom {
40class Geometry;
41class Coordinate;
42class Envelope;
43class GeometryFactory;
44class Polygon;
45class LineString;
46class Point;
47}
48namespace geomgraph {
49class Label;
50class Edge;
51class Node;
52}
53namespace operation {
54namespace overlay {
55class ElevationMatrix;
56}
57}
58}
59
60namespace geos {
61namespace operation { // geos::operation
62namespace overlay { // geos::operation::overlay
63
69class GEOS_DLL OverlayOp: public GeometryGraphOperation {
70
71public:
72
78 enum OpCode {
80 opINTERSECTION = 1,
82 opUNION = 2,
84 opDIFFERENCE = 3,
86 opSYMDIFFERENCE = 4
87 };
88
99 const geom::Geometry* geom1,
100 OpCode opCode);
101 //throw(TopologyException *);
102
115 static bool isResultOfOp(const geomgraph::Label& label, OpCode opCode);
116
121 static bool isResultOfOp(geom::Location loc0, geom::Location loc1, OpCode opCode);
122
129
130 ~OverlayOp() override; // FIXME: virtual ?
131
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
190 static std::unique_ptr<geom::Geometry> createEmptyResult(
191 OverlayOp::OpCode overlayOpCode, const geom::Geometry* a,
192 const geom::Geometry* b, const geom::GeometryFactory* geomFact);
193
194protected:
195
205
206private:
207
208 algorithm::PointLocator ptLocator;
209
210 const geom::GeometryFactory* geomFact;
211
212 geom::Geometry* resultGeom;
213
215
216 geomgraph::EdgeList edgeList;
217
218 std::vector<geom::Polygon*>* resultPolyList;
219
220 std::vector<geom::LineString*>* resultLineList;
221
222 std::vector<geom::Point*>* resultPointList;
223
224 void computeOverlay(OpCode opCode); // throw(TopologyException *);
225
226 void insertUniqueEdges(std::vector<geomgraph::Edge*>* edges, const geom::Envelope* env = nullptr);
227
228 /*
229 * If either of the GeometryLocations for the existing label is
230 * exactly opposite to the one in the labelToMerge,
231 * this indicates a dimensional collapse has happened.
232 * In this case, convert the label for that Geometry to a Line label
233 */
234 //Not needed
235 //void checkDimensionalCollapse(geomgraph::Label labelToMerge, geomgraph::Label existingLabel);
236
248 void computeLabelsFromDepths();
249
254 void replaceCollapsedEdges();
255
266 void copyPoints(uint8_t argIndex, const geom::Envelope* env = nullptr);
267
276 void computeLabelling(); // throw(TopologyException *);
277
285 void mergeSymLabels();
286
287 void updateNodeLabelling();
288
306 void labelIncompleteNodes();
307
311 void labelIncompleteNode(geomgraph::Node* n, uint8_t targetIndex);
312
324 void findResultAreaEdges(OpCode opCode);
325
330 void cancelDuplicateResultEdges();
331
336 bool isCovered(const geom::Coordinate& coord,
337 std::vector<geom::Geometry*>* geomList);
338
343 bool isCovered(const geom::Coordinate& coord,
344 std::vector<geom::Polygon*>* geomList);
345
350 bool isCovered(const geom::Coordinate& coord,
351 std::vector<geom::LineString*>* geomList);
356 static geom::Dimension::DimensionType resultDimension(OverlayOp::OpCode overlayOpCode,
357 const geom::Geometry* g0, const geom::Geometry* g1);
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(uint8_t targetIndex);
392 static double getAverageZ(const geom::Polygon* poly);
393
394 ElevationMatrix* elevationMatrix;
395
398 void checkObviouslyWrongResult(OpCode opCode);
399
400};
401
402} // namespace geos::operation::overlay
403} // namespace geos::operation
404} // namespace geos
405
406#ifdef _MSC_VER
407#pragma warning(pop)
408#endif
409
Computes the topological relationship (Location) of a single point to a Geometry.
Definition: PointLocator.h:56
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:58
DimensionType
Definition: Dimension.h:29
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:58
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:66
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:186
Definition: LineString.h:66
Represents a linear polygon, which may include holes.
Definition: Polygon.h:61
A EdgeList is a list of Edges.
Definition: EdgeList.h:55
Definition: geomgraph/Edge.h:63
A Label indicates the topological relationship of a component of a topology graph to a given Geometry...
Definition: Label.h:57
The node component of a geometry graph.
Definition: geomgraph/Node.h:59
Represents a directed graph which is embeddable in a planar surface.
Definition: geomgraph/PlanarGraph.h:72
The base class for operations that require GeometryGraph.
Definition: GeometryGraphOperation.h:51
Computes the geometric overlay of two Geometry.
Definition: OverlayOp.h:69
static geom::Geometry * overlayOp(const geom::Geometry *geom0, const geom::Geometry *geom1, OpCode opCode)
Computes an overlay operation for the given geometry arguments.
void insertUniqueEdge(geomgraph::Edge *e)
Insert an edge from one of the noded input graphs.
OpCode
The spatial functions supported by this class.
Definition: OverlayOp.h:78
bool isCoveredByLA(const geom::Coordinate &coord)
This method is used to decide if a point node should be included in the result or not.
static bool isResultOfOp(geom::Location loc0, geom::Location loc1, OpCode opCode)
This method will handle arguments of Location.NULL correctly.
static std::unique_ptr< geom::Geometry > createEmptyResult(OverlayOp::OpCode overlayOpCode, const geom::Geometry *a, const geom::Geometry *b, const geom::GeometryFactory *geomFact)
geom::Geometry * getResultGeometry(OpCode overlayOpCode)
Gets the result of the overlay for a given overlay operation.
OverlayOp(const geom::Geometry *g0, const geom::Geometry *g1)
Construct an OverlayOp with the given Geometry args.
bool isCoveredByA(const geom::Coordinate &coord)
This method is used to decide if an L edge should be included in the result or not.
geomgraph::PlanarGraph & getGraph()
Gets the graph constructed to compute the overlay.
Definition: OverlayOp.h:150
static bool isResultOfOp(const geomgraph::Label &label, OpCode opCode)
Tests whether a point with a given topological Label relative to two geometries is contained in the r...
Location
Constants representing the location of a point relative to a geometry.
Definition: Location.h:32
Basic namespace for all GEOS functionalities.
Definition: geos.h:39