/src/gdal/frmts/raw/atlsci_spheroid.cpp
Line | Count | Source |
1 | | /****************************************************************************** |
2 | | * |
3 | | * Project: Spheroid classes |
4 | | * Purpose: Provide spheroid lookup table base classes. |
5 | | * Author: Gillian Walter |
6 | | * |
7 | | ****************************************************************************** |
8 | | * Copyright (c) 1999, Frank Warmerdam |
9 | | * |
10 | | * SPDX-License-Identifier: MIT |
11 | | ****************************************************************************/ |
12 | | |
13 | | #include "atlsci_spheroid.h" |
14 | | #include "cpl_string.h" |
15 | | |
16 | | /**********************************************************************/ |
17 | | /* ================================================================== */ |
18 | | /* Spheroid definitions */ |
19 | | /* ================================================================== */ |
20 | | /**********************************************************************/ |
21 | | |
22 | | SpheroidItem::SpheroidItem() |
23 | 0 | : spheroid_name(nullptr), equitorial_radius(-1.0), polar_radius(-1.0), |
24 | 0 | inverse_flattening(-1.0) |
25 | 0 | { |
26 | 0 | } |
27 | | |
28 | | SpheroidItem::~SpheroidItem() |
29 | 0 | { |
30 | 0 | CPLFree(spheroid_name); |
31 | 0 | } |
32 | | |
33 | | void SpheroidItem::SetValuesByRadii(const char *spheroidname, double eq_radius, |
34 | | double p_radius) |
35 | 0 | { |
36 | 0 | spheroid_name = CPLStrdup(spheroidname); |
37 | 0 | equitorial_radius = eq_radius; |
38 | 0 | polar_radius = p_radius; |
39 | 0 | inverse_flattening = |
40 | 0 | eq_radius == polar_radius ? 0 : eq_radius / (eq_radius - polar_radius); |
41 | 0 | } |
42 | | |
43 | | void SpheroidItem::SetValuesByEqRadiusAndInvFlattening(const char *spheroidname, |
44 | | double eq_radius, |
45 | | double inverseflattening) |
46 | 0 | { |
47 | 0 | spheroid_name = CPLStrdup(spheroidname); |
48 | 0 | equitorial_radius = eq_radius; |
49 | 0 | inverse_flattening = inverseflattening; |
50 | 0 | polar_radius = inverse_flattening == 0 |
51 | 0 | ? eq_radius |
52 | 0 | : eq_radius * (1.0 - (1.0 / inverse_flattening)); |
53 | 0 | } |
54 | | |
55 | 0 | SpheroidList::SpheroidList() : num_spheroids(0), epsilonR(0.0), epsilonI(0.0) |
56 | 0 | { |
57 | 0 | } |
58 | | |
59 | | SpheroidList::~SpheroidList() |
60 | 0 | { |
61 | 0 | } |
62 | | |
63 | | char *SpheroidList::GetSpheroidNameByRadii(double eq_radius, |
64 | | double polar_radius) |
65 | 0 | { |
66 | 0 | for (int index = 0; index < num_spheroids; index++) |
67 | 0 | { |
68 | 0 | const double er = spheroids[index].equitorial_radius; |
69 | 0 | const double pr = spheroids[index].polar_radius; |
70 | 0 | if ((fabs(er - eq_radius) < epsilonR) && |
71 | 0 | (fabs(pr - polar_radius) < epsilonR)) |
72 | 0 | return CPLStrdup(spheroids[index].spheroid_name); |
73 | 0 | } |
74 | | |
75 | 0 | return nullptr; |
76 | 0 | } |
77 | | |
78 | | char *SpheroidList::GetSpheroidNameByEqRadiusAndInvFlattening( |
79 | | double eq_radius, double inverse_flattening) |
80 | 0 | { |
81 | 0 | for (int index = 0; index < num_spheroids; index++) |
82 | 0 | { |
83 | 0 | const double er = spheroids[index].equitorial_radius; |
84 | 0 | const double invf = spheroids[index].inverse_flattening; |
85 | 0 | if ((fabs(er - eq_radius) < epsilonR) && |
86 | 0 | (fabs(invf - inverse_flattening) < epsilonI)) |
87 | 0 | return CPLStrdup(spheroids[index].spheroid_name); |
88 | 0 | } |
89 | | |
90 | 0 | return nullptr; |
91 | 0 | } |
92 | | |
93 | | double SpheroidList::GetSpheroidEqRadius(const char *spheroid_name) |
94 | 0 | { |
95 | 0 | for (int index = 0; index < num_spheroids; index++) |
96 | 0 | { |
97 | 0 | if (EQUAL(spheroids[index].spheroid_name, spheroid_name)) |
98 | 0 | return spheroids[index].equitorial_radius; |
99 | 0 | } |
100 | | |
101 | 0 | return -1.0; |
102 | 0 | } |
103 | | |
104 | | int SpheroidList::SpheroidInList(const char *spheroid_name) |
105 | 0 | { |
106 | | /* Return 1 if the spheroid name is recognized; 0 otherwise */ |
107 | 0 | for (int index = 0; index < num_spheroids; index++) |
108 | 0 | { |
109 | 0 | if (EQUAL(spheroids[index].spheroid_name, spheroid_name)) |
110 | 0 | return 1; |
111 | 0 | } |
112 | | |
113 | 0 | return 0; |
114 | 0 | } |
115 | | |
116 | | double SpheroidList::GetSpheroidInverseFlattening(const char *spheroid_name) |
117 | 0 | { |
118 | 0 | for (int index = 0; index < num_spheroids; index++) |
119 | 0 | { |
120 | 0 | if (EQUAL(spheroids[index].spheroid_name, spheroid_name)) |
121 | 0 | return spheroids[index].inverse_flattening; |
122 | 0 | } |
123 | | |
124 | 0 | return -1.0; |
125 | 0 | } |
126 | | |
127 | | double SpheroidList::GetSpheroidPolarRadius(const char *spheroid_name) |
128 | 0 | { |
129 | 0 | for (int index = 0; index < num_spheroids; index++) |
130 | 0 | { |
131 | 0 | if (strcmp(spheroids[index].spheroid_name, spheroid_name) == 0) |
132 | 0 | return spheroids[index].polar_radius; |
133 | 0 | } |
134 | | |
135 | 0 | return -1.0; |
136 | 0 | } |