GEOS 3.9.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#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
39namespace geos {
40namespace geom {
41class Geometry;
42class Coordinate;
43class Envelope;
44class GeometryFactory;
45class Polygon;
46class LineString;
47class Point;
48}
49namespace geomgraph {
50class Label;
51class Edge;
52class Node;
53}
54namespace operation {
55namespace overlay {
56class ElevationMatrix;
57}
58}
59}
60
61namespace geos {
62namespace operation { // geos::operation
63namespace overlay { // geos::operation::overlay
64
70class GEOS_DLL OverlayOp: public GeometryGraphOperation {
71
72public:
73
79 enum OpCode {
81 opINTERSECTION = 1,
83 opUNION = 2,
85 opDIFFERENCE = 3,
87 opSYMDIFFERENCE = 4
88 };
89
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
130
131 ~OverlayOp() override; // FIXME: virtual ?
132
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
195protected:
196
206
207private:
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
Computes the topological relationship (Location) of a single point to a Geometry.
Definition: PointLocator.h:57
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
DimensionType
Definition: Dimension.h:31
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:68
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:188
Definition: LineString.h:68
Represents a linear polygon, which may include holes.
Definition: Polygon.h:64
A EdgeList is a list of Edges.
Definition: EdgeList.h:58
Definition: geomgraph/Edge.h:66
A Label indicates the topological relationship of a component of a topology graph to a given Geometry...
Definition: Label.h:59
The node component of a geometry graph.
Definition: geomgraph/Node.h:62
Represents a directed graph which is embeddable in a planar surface.
Definition: geomgraph/PlanarGraph.h:75
The base class for operations that require GeometryGraph.
Definition: GeometryGraphOperation.h:52
Computes the geometric overlay of two Geometry.
Definition: OverlayOp.h:70
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:79
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:151
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:34
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:26