GEOS  3.8.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 #ifndef GEOS_OP_OVERLAY_SNAP_SNAPOVERLAYOP_H
20 #define GEOS_OP_OVERLAY_SNAP_SNAPOVERLAYOP_H
21 
22 #include <geos/operation/overlay/OverlayOp.h> // for enums
23 #include <geos/precision/CommonBitsRemover.h> // for dtor visibility by unique_ptr
24 
25 #include <memory> // for unique_ptr
26 
27 #ifdef _MSC_VER
28 #pragma warning(push)
29 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
30 #endif
31 
32 // Forward declarations
33 namespace geos {
34 namespace geom {
35 class Geometry;
36 struct GeomPtrPair;
37 }
38 }
39 
40 namespace geos {
41 namespace operation { // geos::operation
42 namespace overlay { // geos::operation::overlay
43 namespace snap { // geos::operation::overlay::snap
44 
56 class GEOS_DLL SnapOverlayOp {
57 
58 public:
59 
60  static std::unique_ptr<geom::Geometry>
61  overlayOp(const geom::Geometry& g0, const geom::Geometry& g1,
62  OverlayOp::OpCode opCode)
63  {
64  SnapOverlayOp op(g0, g1);
65  return op.getResultGeometry(opCode);
66  }
67 
68  static std::unique_ptr<geom::Geometry>
69  intersection(const geom::Geometry& g0, const geom::Geometry& g1)
70  {
71  return overlayOp(g0, g1, OverlayOp::opINTERSECTION);
72  }
73 
74  static std::unique_ptr<geom::Geometry>
75  Union(const geom::Geometry& g0, const geom::Geometry& g1)
76  {
77  return overlayOp(g0, g1, OverlayOp::opUNION);
78  }
79 
80  static std::unique_ptr<geom::Geometry>
81  difference(const geom::Geometry& g0, const geom::Geometry& g1)
82  {
83  return overlayOp(g0, g1, OverlayOp::opDIFFERENCE);
84  }
85 
86  static std::unique_ptr<geom::Geometry>
87  symDifference(const geom::Geometry& g0, const geom::Geometry& g1)
88  {
89  return overlayOp(g0, g1, OverlayOp::opSYMDIFFERENCE);
90  }
91 
92  SnapOverlayOp(const geom::Geometry& g1, const geom::Geometry& g2)
93  :
94  geom0(g1),
95  geom1(g2)
96  {
97  computeSnapTolerance();
98  }
99 
100 
101  typedef std::unique_ptr<geom::Geometry> GeomPtr;
102 
103  GeomPtr getResultGeometry(OverlayOp::OpCode opCode);
104 
105 private:
106 
107  void computeSnapTolerance();
108 
109  void snap(geom::GeomPtrPair& ret);
110 
111  void removeCommonBits(const geom::Geometry& geom0,
112  const geom::Geometry& geom1,
113  geom::GeomPtrPair& ret);
114 
115  // re-adds common bits to the given geom
116  void prepareResult(geom::Geometry& geom);
117 
118 
119  const geom::Geometry& geom0;
120  const geom::Geometry& geom1;
121 
122  double snapTolerance;
123 
124  std::unique_ptr<precision::CommonBitsRemover> cbr;
125 
126  // Declare type as noncopyable
127  SnapOverlayOp(const SnapOverlayOp& other) = delete;
128  SnapOverlayOp& operator=(const SnapOverlayOp& rhs) = delete;
129 };
130 
131 } // namespace geos::operation::overlay::snap
132 } // namespace geos::operation::overlay
133 } // namespace geos::operation
134 } // namespace geos
135 
136 #ifdef _MSC_VER
137 #pragma warning(pop)
138 #endif
139 
140 #endif // ndef GEOS_OP_OVERLAY_SNAP_SNAPOVERLAYOP_H
The code for the Intersection overlay operation.
Definition: OverlayOp.h:81
The code for the Union overlay operation.
Definition: OverlayOp.h:83
Performs an overlay operation using snapping and enhanced precision to improve the robustness of the ...
Definition: SnapOverlayOp.h:56
OpCode
The spatial functions supported by this class.
Definition: OverlayOp.h:79
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:188
The code for the Difference overlay operation.
Definition: OverlayOp.h:85
OverlayOp::overlayOp Adapter for use with geom::BinaryOp.
Definition: OverlayOp.h:406
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25
The code for the Symmetric Difference overlay operation.
Definition: OverlayOp.h:87