OmniSciDB  6686921089
 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 2021 OmniSci, 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 #include <cmath>
20 
21 extern "C" ALWAYS_INLINE double transform_4326_900913_x(const double x, double) {
22  constexpr double a = 6378137; // WGS84 Equatorial radius (m)
23  constexpr double rad_div_deg = M_PI / 180;
24  constexpr double c = a * rad_div_deg;
25  return c * x;
26 }
27 
28 // Required: -90 < y < 90 otherwise log() may be calculated for a negative number.
29 extern "C" ALWAYS_INLINE double transform_4326_900913_y(double, const double y) {
30  constexpr double a = 6378137; // WGS84 Equatorial radius (m)
31  constexpr double rad_div_two_deg = M_PI / (2 * 180);
32  constexpr double pi_div_four = M_PI / 4;
33  return a * log(tan(rad_div_two_deg * y + pi_div_four));
34 }
35 
36 extern "C" ALWAYS_INLINE double transform_900913_4326_x(const double x, double) {
37  constexpr double a = 6378137; // WGS84 Equatorial radius (m)
38  constexpr double deg_div_rad = 180 / M_PI;
39  constexpr double c = deg_div_rad / a;
40  return c * x;
41 }
42 
43 extern "C" ALWAYS_INLINE double transform_900913_4326_y(double, const double y) {
44  constexpr double a = 6378137; // WGS84 Equatorial radius (m)
45  constexpr double a_inv = 1 / a;
46  constexpr double two_deg_div_rad = 2 * 180 / M_PI;
47  return two_deg_div_rad * atan(exp(a_inv * y)) - 90;
48 }
49 
50 extern "C" ALWAYS_INLINE double transform_4326_utm_x(unsigned const utm_srid,
51  double const x,
52  double const y) {
53  return Transform4326ToUTM(utm_srid, x, y).calculateX();
54 }
55 
56 extern "C" ALWAYS_INLINE double transform_4326_utm_y(unsigned const utm_srid,
57  double const x,
58  double const y) {
59  return Transform4326ToUTM(utm_srid, x, y).calculateY();
60 }
61 
62 extern "C" ALWAYS_INLINE double transform_utm_4326_x(unsigned const utm_srid,
63  double const x,
64  double const y) {
65  return TransformUTMTo4326(utm_srid, x, y).calculateX();
66 }
67 
68 extern "C" ALWAYS_INLINE double transform_utm_4326_y(unsigned const utm_srid,
69  double const x,
70  double const y) {
71  return TransformUTMTo4326(utm_srid, x, y).calculateY();
72 }
73 
74 extern "C" ALWAYS_INLINE double transform_900913_utm_x(unsigned const utm_srid,
75  double const x,
76  double const y) {
77  return transform_4326_utm_x(
78  utm_srid, transform_900913_4326_x(x, {}), transform_900913_4326_y({}, y));
79 }
80 
81 extern "C" ALWAYS_INLINE double transform_900913_utm_y(unsigned const utm_srid,
82  double const x,
83  double const y) {
84  return transform_4326_utm_y(
85  utm_srid, transform_900913_4326_x(x, {}), transform_900913_4326_y({}, y));
86 }
87 
88 extern "C" ALWAYS_INLINE double transform_utm_900913_x(unsigned const utm_srid,
89  double const x,
90  double const y) {
91  return transform_4326_900913_x(transform_utm_4326_x(utm_srid, x, y), {});
92 }
93 
94 extern "C" ALWAYS_INLINE double transform_utm_900913_y(unsigned const utm_srid,
95  double const x,
96  double const y) {
97  return transform_4326_900913_y({}, transform_utm_4326_y(utm_srid, x, y));
98 }
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)
ALWAYS_INLINE double calculateY() const
Definition: Utm.h:197
ALWAYS_INLINE double transform_4326_utm_x(unsigned const utm_srid, double const x, double const y)
ALWAYS_INLINE double transform_utm_4326_x(unsigned const utm_srid, double const x, double const y)
constexpr double rad_div_deg
Definition: Utm.h:42
#define M_PI
Definition: constants.h:25
constexpr double a
Definition: Utm.h:38
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)
ALWAYS_INLINE double calculateX() const
Definition: Utm.h:172
ALWAYS_INLINE double calculateY() const
Definition: Utm.h:263
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)
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
constexpr double deg_div_rad
Definition: Utm.h:41