MySQL 8.4.2
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, 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/// Implements a longitude normalizer that converts longitude coordinates
30/// outside the range such that geometries wrap correctly across
31/// the 180/-180 boundary on the globe.
32
33#include <cmath> // M_PI
34
35#include "sql/dd/types/spatial_reference_system.h" // dd::Spatial_reference_system
37
38namespace gis {
39
41 private:
43
44 public:
45 /// Construct a new longitude range normalizer.
46 ///
47 /// @param srs The spatial reference system of the geometry.
49 : m_srs(srs) {}
50
52 bool visit(Point *pt) override {
53 double lon = pt->x() - m_srs->prime_meridian() * m_srs->angular_unit();
54 if (!m_srs->positive_east()) lon *= -1.0;
55 if (lon <= -M_PI) {
56 // Longitude -180 or less, so we add 360 (2*pi): e.g. -182 + 360 = 178
57 pt->x(lon + 2.0 * M_PI);
58 } else if (lon > M_PI) {
59 // Longitude over 180, so we subtract 360 (2*pi): e.g. 181 - 360 = -179
60 pt->x(lon - 2.0 * M_PI);
61 }
62 return false;
63 }
64};
65
66} // namespace gis
67
68#endif // SQL_GIS_LONGITUDE_RANGE_NORMALIZER_H_INCLUDED
Definition: spatial_reference_system.h:53
virtual double angular_unit() const =0
virtual bool positive_east() const =0
virtual double prime_meridian() const =0
Definition: longitude_range_normalizer.h:40
Longitude_range_normalizer(const dd::Spatial_reference_system *srs)
Construct a new longitude range normalizer.
Definition: longitude_range_normalizer.h:48
const dd::Spatial_reference_system * m_srs
Definition: longitude_range_normalizer.h:42
bool visit(Point *pt) override
Definition: longitude_range_normalizer.h:52
A visitor that implements the entire interface and does nothing.
Definition: geometry_visitor.h:122
bool visit(Geometry *) override
Visits a geometry.
Definition: geometry_visitor.h:159
A 2d point.
Definition: geometries.h:150
double x() const
Gets the first coordinate value.
Definition: geometries.cc:46
The geometries implement a hierarchical visitor pattern.
Definition: area.cc:47