MySQL 9.1.0
Source Code Documentation
gc_utils.h
Go to the documentation of this file.
1#ifndef SQL_GIS_GC_UTILS_H_INCLUDED
2#define SQL_GIS_GC_UTILS_H_INCLUDED
3
4// Copyright (c) 2017, 2024, Oracle and/or its affiliates.
5//
6// This program is free software; you can redistribute it and/or modify
7// it under the terms of the GNU General Public License, version 2.0,
8// as published by the Free Software Foundation.
9//
10// This program is designed to work with certain software (including
11// but not limited to OpenSSL) that is licensed under separate terms,
12// as designated in a particular file or component or in included license
13// documentation. The authors of MySQL hereby grant you an additional
14// permission to link the program and your derivative works with the
15// separately licensed software that they have either included with
16// the program or referenced in the documentation.
17//
18// This program is distributed in the hope that it will be useful,
19// but WITHOUT ANY WARRANTY; without even the implied warranty of
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21// GNU General Public License, version 2.0, for more details.
22//
23// You should have received a copy of the GNU General Public License
24// along with this program; if not, write to the Free Software
25// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
26
27/// @file
28///
29/// This file declares the interface of various utility functions for
30/// geometrycollections. The functions may throw exceptions.
31
32#include <memory> // std::unique_ptr
33
34#include "sql/dd/types/spatial_reference_system.h" // dd::Spatial_reference_system
36#include "sql/gis/geometries.h"
38
39namespace gis {
40
41/// Invalid geometry exception.
42///
43/// Thrown when it is discovered that at an input parameter contains an invalid
44/// geometry.
45class invalid_geometry_exception : public std::exception {};
46
47/// Too large polygon exception.
48///
49/// Thrown when it is discovered that at a polygon covers half the globe or
50/// more. Boost Geometry doesn't handle such polygons.
51class too_large_polygon_exception : public std::exception {};
52
53/// Splits a geometrycollection into points, linestrings and polygons.
54///
55/// All output collections may contain overlapping geometries and
56/// duplicates. This is not a problem for the multipoint and multilinestring
57/// outputs, but the multipolygon may be geometrically invalid.
58///
59/// @param[in] gc Geometry collection.
60/// @param[out] mpt All points in the geometrycollection.
61/// @param[out] mls All linestrings in the geometrycollection.
62/// @param[out] mpy All polygons in the geometrycollection.
63void split_gc(const Geometrycollection *gc, std::unique_ptr<Multipoint> *mpt,
64 std::unique_ptr<Multilinestring> *mls,
65 std::unique_ptr<Multipolygon> *mpy);
66
67/// Cleans up overlapping geometries so that the geometrycollection is broken
68/// down into non-overlapping collections.
69///
70/// All input collections may contain overlapping geometries and
71/// duplicates, including the multipolygon. This function requires that at least
72/// one of the inputs must be non-empty.
73///
74/// May throw exceptions from BG operations.
75///
76/// @param[in] semi_major Semi-major axis of ellipsoid.
77/// @param[in] semi_minor Semi-minor axis of ellipsoid.
78/// @param[in,out] mpt All points in the geometrycollection.
79/// @param[in,out] mls All linestrings in the geometrycollection.
80/// @param[in,out] mpy All polygons in the geometrycollection.
81void gc_union(double semi_major, double semi_minor,
82 std::unique_ptr<Multipoint> *mpt,
83 std::unique_ptr<Multilinestring> *mls,
84 std::unique_ptr<Multipolygon> *mpy);
85
86/// Narrows down a geometrycollection to return a Multipoint, Multilinestring
87/// or a Multipolygon if the first level of the geometrycollection contains
88/// only points, linestrings or polygons. Otherwise, if the contents is
89/// heterogeneous or contains a geometrycollection, returns the input
90/// geometrycollection.
91///
92/// @param[in] geometrycollection Geometrycollection to be narroweed down.
93/// @return The narrowest type that can contain all the geometries in the input.
94std::unique_ptr<gis::Geometrycollection> narrowest_multigeometry(
95 std::unique_ptr<Geometrycollection> geometrycollection);
96} // namespace gis
97
98#endif // SQL_GIS_GC_UTILS_H_INCLUDED
A collection of geometries.
Definition: geometries.h:410
Invalid geometry exception.
Definition: gc_utils.h:45
Too large polygon exception.
Definition: gc_utils.h:51
This file declares the difference functor interface.
This file declares the geometry class hierarchy used by the server as the internal representation of ...
Definition: area.cc:47
std::unique_ptr< gis::Geometrycollection > narrowest_multigeometry(std::unique_ptr< gis::Geometrycollection > geometrycollection)
Narrows down a geometrycollection to return a Multipoint, Multilinestring or a Multipolygon if the fi...
Definition: gc_utils.cc:213
void gc_union(double semi_major, double semi_minor, std::unique_ptr< Multipoint > *mpt, std::unique_ptr< Multilinestring > *mls, std::unique_ptr< Multipolygon > *mpy)
Cleans up overlapping geometries so that the geometrycollection is broken down into non-overlapping c...
Definition: gc_utils.cc:178
void split_gc(const Geometrycollection *gc, std::unique_ptr< Multipoint > *mpt, std::unique_ptr< Multilinestring > *mls, std::unique_ptr< Multipolygon > *mpy)
Splits a geometrycollection into points, linestrings and polygons.
Definition: gc_utils.cc:92
This file declares the union functor interface.