MySQL 8.0.30
Source Code Documentation
longitude_range_normalizer.h
Go to the documentation of this file.
1#ifndef SQL_GIS_LONGITUDE_RANGE_NORMALIZER_H_INCLUDED
2#define SQL_GIS_LONGITUDE_RANGE_NORMALIZER_H_INCLUDED
3
4// Copyright (c) 2021, 2022, 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 also distributed 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 included with MySQL.
16//
17// This program is distributed in the hope that it will be useful,
18// but WITHOUT ANY WARRANTY; without even the implied warranty of
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20// GNU General Public License, version 2.0, for more details.
21//
22// You should have received a copy of the GNU General Public License
23// along with this program; if not, write to the Free Software
24// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
25
26/// @file
27///
28/// Implements a longitude normalizer that converts longitude coordinates
29/// outside the range such that geometries wrap correctly across
30/// the 180/-180 boundary on the globe.
31
32#include <cmath> // M_PI
33
34#include "sql/dd/types/spatial_reference_system.h" // dd::Spatial_reference_system
36
37namespace gis {
38
40 private:
42
43 public:
44 /// Construct a new longitude range normalizer.
45 ///
46 /// @param srs The spatial reference system of the geometry.
48 : m_srs(srs) {}
49
51 bool visit(Point *pt) override {
52 double lon = pt->x() - m_srs->prime_meridian() * m_srs->angular_unit();
53 if (!m_srs->positive_east()) lon *= -1.0;
54 if (lon <= -M_PI) {
55 // Longitude -180 or less, so we add 360 (2*pi): e.g. -182 + 360 = 178
56 pt->x(lon + 2.0 * M_PI);
57 } else if (lon > M_PI) {
58 // Longitude over 180, so we subtract 360 (2*pi): e.g. 181 - 360 = -179
59 pt->x(lon - 2.0 * M_PI);
60 }
61 return false;
62 }
63};
64
65} // namespace gis
66
67#endif // SQL_GIS_LONGITUDE_RANGE_NORMALIZER_H_INCLUDED
Definition: spatial_reference_system.h:52
virtual double angular_unit() const =0
virtual bool positive_east() const =0
virtual double prime_meridian() const =0
Definition: longitude_range_normalizer.h:39
Longitude_range_normalizer(const dd::Spatial_reference_system *srs)
Construct a new longitude range normalizer.
Definition: longitude_range_normalizer.h:47
const dd::Spatial_reference_system * m_srs
Definition: longitude_range_normalizer.h:41
bool visit(Point *pt) override
Definition: longitude_range_normalizer.h:51
A visitor that implements the entire interface and does nothing.
Definition: geometry_visitor.h:121
bool visit(Geometry *) override
Visits a geometry.
Definition: geometry_visitor.h:158
A 2d point.
Definition: geometries.h:149
double x() const
Gets the first coordinate value.
Definition: geometries.cc:45
The geometries implement a hierarchical visitor pattern.
Definition: area.cc:46