OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GeoOpsRuntime.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "Geospatial/Utm.h"
18 
19 extern "C" ALWAYS_INLINE double transform_4326_900913_x(const double x, double) {
20  constexpr double a = 6378137; // WGS84 Equatorial radius (m)
21  constexpr double c = a * math_consts::rad_div_deg;
22  return c * x;
23 }
24 
25 // Required: -90 < y < 90 otherwise log() may be calculated for a negative number.
26 extern "C" ALWAYS_INLINE double transform_4326_900913_y(double, const double y) {
27  constexpr double a = 6378137; // WGS84 Equatorial radius (m)
28  constexpr double rad_div_two_deg = math_consts::m_pi / (2 * 180);
29  constexpr double pi_div_four = math_consts::m_pi / 4;
30  return a * log(tan(rad_div_two_deg * y + pi_div_four));
31 }
32 
33 extern "C" ALWAYS_INLINE double transform_900913_4326_x(const double x, double) {
34  constexpr double a = 6378137; // WGS84 Equatorial radius (m)
35  constexpr double c = math_consts::deg_div_rad / a;
36  return c * x;
37 }
38 
39 extern "C" ALWAYS_INLINE double transform_900913_4326_y(double, const double y) {
40  constexpr double a = 6378137; // WGS84 Equatorial radius (m)
41  constexpr double a_inv = 1 / a;
42  constexpr double two_deg_div_rad = 2 * 180 / math_consts::m_pi;
43  return two_deg_div_rad * atan(exp(a_inv * y)) - 90;
44 }
45 
46 extern "C" ALWAYS_INLINE double transform_4326_utm_x(unsigned const utm_srid,
47  double const x,
48  double const y) {
49  return Transform4326ToUTM(utm_srid, x, y).calculateX();
50 }
51 
52 extern "C" ALWAYS_INLINE double transform_4326_utm_y(unsigned const utm_srid,
53  double const x,
54  double const y) {
55  return Transform4326ToUTM(utm_srid, x, y).calculateY();
56 }
57 
58 extern "C" ALWAYS_INLINE double transform_utm_4326_x(unsigned const utm_srid,
59  double const x,
60  double const y) {
61  return TransformUTMTo4326(utm_srid, x, y).calculateX();
62 }
63 
64 extern "C" ALWAYS_INLINE double transform_utm_4326_y(unsigned const utm_srid,
65  double const x,
66  double const y) {
67  return TransformUTMTo4326(utm_srid, x, y).calculateY();
68 }
69 
70 extern "C" ALWAYS_INLINE double transform_900913_utm_x(unsigned const utm_srid,
71  double const x,
72  double const y) {
73  return transform_4326_utm_x(
74  utm_srid, transform_900913_4326_x(x, {}), transform_900913_4326_y({}, y));
75 }
76 
77 extern "C" ALWAYS_INLINE double transform_900913_utm_y(unsigned const utm_srid,
78  double const x,
79  double const y) {
80  return transform_4326_utm_y(
81  utm_srid, transform_900913_4326_x(x, {}), transform_900913_4326_y({}, y));
82 }
83 
84 extern "C" ALWAYS_INLINE double transform_utm_900913_x(unsigned const utm_srid,
85  double const x,
86  double const y) {
87  return transform_4326_900913_x(transform_utm_4326_x(utm_srid, x, y), {});
88 }
89 
90 extern "C" ALWAYS_INLINE double transform_utm_900913_y(unsigned const utm_srid,
91  double const x,
92  double const y) {
93  return transform_4326_900913_y({}, transform_utm_4326_y(utm_srid, x, y));
94 }
ALWAYS_INLINE double transform_900913_4326_y(double, const double y)
ALWAYS_INLINE double transform_900913_utm_x(unsigned const utm_srid, double const x, double const y)
ALWAYS_INLINE double transform_4326_900913_y(double, const double y)
DEVICE ALWAYS_INLINE double calculateY() const
Definition: Utm.h:195
ALWAYS_INLINE double transform_4326_utm_x(unsigned const utm_srid, double const x, double const y)
constexpr double m_pi
Definition: math_consts.h:20
constexpr double deg_div_rad
Definition: math_consts.h:22
ALWAYS_INLINE double transform_utm_4326_x(unsigned const utm_srid, double const x, double const y)
constexpr double rad_div_deg
Definition: math_consts.h:21
constexpr double a
Definition: Utm.h:32
ALWAYS_INLINE double transform_900913_utm_y(unsigned const utm_srid, double const x, double const y)
ALWAYS_INLINE double transform_4326_utm_y(unsigned const utm_srid, double const x, double const y)
ALWAYS_INLINE double transform_900913_4326_x(const double x, double)
DEVICE ALWAYS_INLINE double calculateY() const
Definition: Utm.h:263
DEVICE ALWAYS_INLINE double calculateX() const
Definition: Utm.h:170
ALWAYS_INLINE double transform_4326_900913_x(const double x, double)
Convert to/from WGS84 (long,lat) and UTM (x,y) given utm zone srid.
ALWAYS_INLINE double transform_utm_900913_x(unsigned const utm_srid, double const x, double const y)
DEVICE ALWAYS_INLINE double calculateX() const
Definition: Utm.h:255
ALWAYS_INLINE double transform_utm_900913_y(unsigned const utm_srid, double const x, double const y)
ALWAYS_INLINE double transform_utm_4326_y(unsigned const utm_srid, double const x, double const y)
#define ALWAYS_INLINE