1 // Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2 //
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License, version 2.0,
5 // as published by the Free Software Foundation.
6 //
7 // This program is also distributed with certain software (including
8 // but not limited to OpenSSL) that is licensed under separate terms,
9 // as designated in a particular file or component or in included license
10 // documentation. The authors of MySQL hereby grant you an additional
11 // permission to link the program and your derivative works with the
12 // separately licensed software that they have included with MySQL.
13 //
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License, version 2.0, for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22
23 /// @file
24 ///
25 /// This file implements the union functor and function.
26
27 #include <memory> // std::unique_ptr
28
29 #include <boost/geometry.hpp>
30
31 #include "sql/gis/geometries.h"
32 #include "sql/gis/geometries_traits.h"
33 #include "sql/gis/union_functor.h"
34
35 namespace bg = boost::geometry;
36
37 namespace gis {
38
Union(double semi_major,double semi_minor)39 Union::Union(double semi_major, double semi_minor)
40 : m_semi_major(semi_major),
41 m_semi_minor(semi_minor),
42 m_geographic_pl_pa_strategy(
43 bg::srs::spheroid<double>(semi_major, semi_minor)),
44 m_geographic_ll_la_aa_strategy(
45 bg::srs::spheroid<double>(semi_major, semi_minor)) {}
46
operator ()(const Geometry * g1,const Geometry * g2) const47 Geometry *Union::operator()(const Geometry *g1, const Geometry *g2) const {
48 return apply(*this, g1, g2);
49 }
50
eval(const Geometry * g1,const Geometry * g2) const51 Geometry *Union::eval(const Geometry *g1, const Geometry *g2) const {
52 DBUG_ASSERT(false);
53 throw not_implemented_exception::for_non_projected(*g1, *g2);
54 }
55
56 //////////////////////////////////////////////////////////////////////////////
57
58 // union(Cartesian_multilinestring, *)
59
eval(const Cartesian_multilinestring * g1,const Cartesian_linestring * g2) const60 Geometry *Union::eval(const Cartesian_multilinestring *g1,
61 const Cartesian_linestring *g2) const {
62 std::unique_ptr<Cartesian_multilinestring> result(
63 new Cartesian_multilinestring());
64 bg::union_(*g1, *g2, *result);
65 return result.release();
66 }
67
68 //////////////////////////////////////////////////////////////////////////////
69
70 // union(Cartesian_multipolygon, *)
71
eval(const Cartesian_multipolygon * g1,const Cartesian_polygon * g2) const72 Geometry *Union::eval(const Cartesian_multipolygon *g1,
73 const Cartesian_polygon *g2) const {
74 std::unique_ptr<Cartesian_multipolygon> result(new Cartesian_multipolygon());
75 bg::union_(*g1, *g2, *result);
76 return result.release();
77 }
78
79 //////////////////////////////////////////////////////////////////////////////
80
81 // union(Geographic_multilinestring, *)
82
eval(const Geographic_multilinestring * g1,const Geographic_linestring * g2) const83 Geometry *Union::eval(const Geographic_multilinestring *g1,
84 const Geographic_linestring *g2) const {
85 std::unique_ptr<Geographic_multilinestring> result(
86 new Geographic_multilinestring());
87 bg::union_(*g1, *g2, *result, m_geographic_ll_la_aa_strategy);
88 return result.release();
89 }
90
91 //////////////////////////////////////////////////////////////////////////////
92
93 // union(Geographic_multipolygon, *)
94
eval(const Geographic_multipolygon * g1,const Geographic_polygon * g2) const95 Geometry *Union::eval(const Geographic_multipolygon *g1,
96 const Geographic_polygon *g2) const {
97 std::unique_ptr<Geographic_multipolygon> result(
98 new Geographic_multipolygon());
99 bg::union_(*g1, *g2, *result, m_geographic_ll_la_aa_strategy);
100 return result.release();
101 }
102
103 } // namespace gis
104