GEOS  3.11.0beta2
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/operation/overlay/OverlayOp.h> // for enums
22 #include <geos/precision/CommonBitsRemover.h> // for dtor visibility by unique_ptr
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
32 namespace geos {
33 namespace geom {
34 class Geometry;
35 struct GeomPtrPair;
36 }
37 }
38 
39 namespace geos {
40 namespace operation { // geos::operation
41 namespace overlay { // geos::operation::overlay
42 namespace snap { // geos::operation::overlay::snap
43 
55 class GEOS_DLL SnapOverlayOp {
56 
57 public:
58 
59  static std::unique_ptr<geom::Geometry>
60  overlayOp(const geom::Geometry& g0, const geom::Geometry& g1,
61  OverlayOp::OpCode opCode)
62  {
63  SnapOverlayOp op(g0, g1);
64  return op.getResultGeometry(opCode);
65  }
66 
67  static std::unique_ptr<geom::Geometry>
68  intersection(const geom::Geometry& g0, const geom::Geometry& g1)
69  {
70  return overlayOp(g0, g1, OverlayOp::opINTERSECTION);
71  }
72 
73  static std::unique_ptr<geom::Geometry>
74  Union(const geom::Geometry& g0, const geom::Geometry& g1)
75  {
76  return overlayOp(g0, g1, OverlayOp::opUNION);
77  }
78 
79  static std::unique_ptr<geom::Geometry>
80  difference(const geom::Geometry& g0, const geom::Geometry& g1)
81  {
82  return overlayOp(g0, g1, OverlayOp::opDIFFERENCE);
83  }
84 
85  static std::unique_ptr<geom::Geometry>
86  symDifference(const geom::Geometry& g0, const geom::Geometry& g1)
87  {
88  return overlayOp(g0, g1, OverlayOp::opSYMDIFFERENCE);
89  }
90 
91  SnapOverlayOp(const geom::Geometry& g1, const geom::Geometry& g2)
92  :
93  geom0(g1),
94  geom1(g2)
95  {
96  computeSnapTolerance();
97  }
98 
99 
100  typedef std::unique_ptr<geom::Geometry> GeomPtr;
101 
102  GeomPtr getResultGeometry(OverlayOp::OpCode opCode);
103 
104 private:
105 
106  void computeSnapTolerance();
107 
108  void snap(geom::GeomPtrPair& ret);
109 
110  void removeCommonBits(const geom::Geometry& geom0,
111  const geom::Geometry& geom1,
112  geom::GeomPtrPair& ret);
113 
114  // re-adds common bits to the given geom
115  void prepareResult(geom::Geometry& geom);
116 
117 
118  const geom::Geometry& geom0;
119  const geom::Geometry& geom1;
120 
121  double snapTolerance;
122 
123  std::unique_ptr<precision::CommonBitsRemover> cbr;
124 
125  // Declare type as noncopyable
126  SnapOverlayOp(const SnapOverlayOp& other) = delete;
127  SnapOverlayOp& operator=(const SnapOverlayOp& rhs) = delete;
128 };
129 
130 } // namespace geos::operation::overlay::snap
131 } // namespace geos::operation::overlay
132 } // namespace geos::operation
133 } // namespace geos
134 
135 #ifdef _MSC_VER
136 #pragma warning(pop)
137 #endif
138 
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:186
OpCode
The spatial functions supported by this class.
Definition: OverlayOp.h:78
@ opSYMDIFFERENCE
The code for the Symmetric Difference overlay operation.
Definition: OverlayOp.h:86
@ opUNION
The code for the Union overlay operation.
Definition: OverlayOp.h:82
@ opINTERSECTION
The code for the Intersection overlay operation.
Definition: OverlayOp.h:80
@ opDIFFERENCE
The code for the Difference overlay operation.
Definition: OverlayOp.h:84
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: Angle.h:25