GEOS 3.14.0dev
SnapOverlayOp.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2009 Sandro Santilli <strk@kbt.io>
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/snap/SnapOverlayOp.java r320 (JTS-1.12)
16 *
17 **********************************************************************/
18
19#pragma once
20
21#include <geos/precision/CommonBitsRemover.h> // for dtor visibility by unique_ptr
22#include <geos/operation/overlayng/OverlayNG.h>
23
24#include <memory> // for unique_ptr
25
26#ifdef _MSC_VER
27#pragma warning(push)
28#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
29#endif
30
31// Forward declarations
32namespace geos {
33namespace geom {
34class Geometry;
35struct GeomPtrPair;
36}
37}
38
39namespace geos {
40namespace operation { // geos::operation
41namespace overlay { // geos::operation::overlay
42namespace snap { // geos::operation::overlay::snap
43
55class GEOS_DLL SnapOverlayOp {
56
57public:
58
59 static std::unique_ptr<geom::Geometry>
60 overlayOp(const geom::Geometry& g0, const geom::Geometry& g1, int opCode)
61 {
62 SnapOverlayOp op(g0, g1);
63 return op.getResultGeometry(opCode);
64 }
65
66 static std::unique_ptr<geom::Geometry>
67 intersection(const geom::Geometry& g0, const geom::Geometry& g1)
68 {
69 return overlayOp(g0, g1, overlayng::OverlayNG::INTERSECTION);
70 }
71
72 static std::unique_ptr<geom::Geometry>
73 Union(const geom::Geometry& g0, const geom::Geometry& g1)
74 {
75 return overlayOp(g0, g1, overlayng::OverlayNG::UNION);
76 }
77
78 static std::unique_ptr<geom::Geometry>
79 difference(const geom::Geometry& g0, const geom::Geometry& g1)
80 {
81 return overlayOp(g0, g1, overlayng::OverlayNG::DIFFERENCE);
82 }
83
84 static std::unique_ptr<geom::Geometry>
85 symDifference(const geom::Geometry& g0, const geom::Geometry& g1)
86 {
87 return overlayOp(g0, g1, overlayng::OverlayNG::SYMDIFFERENCE);
88 }
89
90 SnapOverlayOp(const geom::Geometry& g1, const geom::Geometry& g2)
91 :
92 geom0(g1),
93 geom1(g2)
94 {
95 computeSnapTolerance();
96 }
97
98 std::unique_ptr<geom::Geometry> getResultGeometry(int opCode);
99
100private:
101
102 void computeSnapTolerance();
103
104 void snap(geom::GeomPtrPair& ret);
105
106 void removeCommonBits(const geom::Geometry& geom0,
107 const geom::Geometry& geom1,
108 geom::GeomPtrPair& ret);
109
110 // re-adds common bits to the given geom
111 void prepareResult(geom::Geometry& geom);
112
113
114 const geom::Geometry& geom0;
115 const geom::Geometry& geom1;
116
117 double snapTolerance;
118
119 std::unique_ptr<precision::CommonBitsRemover> cbr;
120
121 // Declare type as noncopyable
122 SnapOverlayOp(const SnapOverlayOp& other) = delete;
123 SnapOverlayOp& operator=(const SnapOverlayOp& rhs) = delete;
124};
125
126} // namespace geos::operation::overlay::snap
127} // namespace geos::operation::overlay
128} // namespace geos::operation
129} // namespace geos
130
131#ifdef _MSC_VER
132#pragma warning(pop)
133#endif
134
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:197
Performs an overlay operation using snapping and enhanced precision to improve the robustness of the ...
Definition SnapOverlayOp.h:55
Basic namespace for all GEOS functionalities.
Definition geos.h:39