GEOS 3.4.2

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List

SnapOverlayOp.h
1 /**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2009 Sandro Santilli <strk@keybit.net>
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 auto_ptr
24
25 #include <memory> // for auto_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
59 public:
60
61 static std::auto_ptr<geom::Geometry>
62 overlayOp(const geom::Geometry& g0, const geom::Geometry& g1,
63 OverlayOp::OpCode opCode)
64 {
65 SnapOverlayOp op(g0, g1);
66 return op.getResultGeometry(opCode);
67 }
68
69 static std::auto_ptr<geom::Geometry>
70 intersection(const geom::Geometry& g0, const geom::Geometry& g1)
71 {
72 return overlayOp(g0, g1, OverlayOp::opINTERSECTION);
73 }
74
75 static std::auto_ptr<geom::Geometry>
76 Union(const geom::Geometry& g0, const geom::Geometry& g1)
77 {
78 return overlayOp(g0, g1, OverlayOp::opUNION);
79 }
80
81 static std::auto_ptr<geom::Geometry>
82 difference(const geom::Geometry& g0, const geom::Geometry& g1)
83 {
84 return overlayOp(g0, g1, OverlayOp::opDIFFERENCE);
85 }
86
87 static std::auto_ptr<geom::Geometry>
88 symDifference(const geom::Geometry& g0, const geom::Geometry& g1)
89 {
90 return overlayOp(g0, g1, OverlayOp::opSYMDIFFERENCE);
91 }
92
93 SnapOverlayOp(const geom::Geometry& g1, const geom::Geometry& g2)
94 :
95 geom0(g1),
96 geom1(g2)
97 {
98 computeSnapTolerance();
99 }
100
101
102 typedef std::auto_ptr<geom::Geometry> GeomPtr;
103
104 GeomPtr getResultGeometry(OverlayOp::OpCode opCode);
105
106 private:
107
108 void computeSnapTolerance();
109
110 void snap(geom::GeomPtrPair& ret);
111
112 void removeCommonBits(const geom::Geometry& geom0,
113 const geom::Geometry& geom1,
114 geom::GeomPtrPair& ret);
115
116 // re-adds common bits to the given geom
117 void prepareResult(geom::Geometry& geom);
118
119
120 const geom::Geometry& geom0;
121 const geom::Geometry& geom1;
122
123 double snapTolerance;
124
125 std::auto_ptr<precision::CommonBitsRemover> cbr;
126
127 // Declare type as noncopyable
128 SnapOverlayOp(const SnapOverlayOp& other);
129 SnapOverlayOp& operator=(const SnapOverlayOp& rhs);
130 };
131
132 } // namespace geos::operation::overlay::snap
133 } // namespace geos::operation::overlay
134 } // namespace geos::operation
135 } // namespace geos
136
137 #ifdef _MSC_VER
138 #pragma warning(pop)
139 #endif
140
141 #endif // ndef GEOS_OP_OVERLAY_SNAP_SNAPOVERLAYOP_H