GEOS 3.8.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
66//
70class GEOS_DLL OverlayOp: public GeometryGraphOperation {
71
72public:
73
75 //
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
119 //
122 static bool isResultOfOp(geom::Location loc0, geom::Location loc1, OpCode opCode);
123
125 //
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
178protected:
179
189
190private:
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 std::unique_ptr<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
406struct 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
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
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:58
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.
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:25
OverlayOp::overlayOp Adapter for use with geom::BinaryOp.
Definition: OverlayOp.h:406