File: Geoid.h

package info (click to toggle)
geographiclib 1.37-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 9,688 kB
  • ctags: 4,871
  • sloc: cpp: 31,440; sh: 11,632; cs: 9,411; ansic: 1,428; java: 1,333; python: 1,131; makefile: 758; xml: 381; pascal: 30
file content (379 lines) | stat: -rw-r--r-- 17,823 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
#pragma once
/**
 * \file NETGeographicLib/Geoid.h
 * \brief Header for NETGeographicLib::Geoid class
 *
 * NETGeographicLib is copyright (c) Scott Heiman (2013)
 * GeographicLib is Copyright (c) Charles Karney (2010-2012)
 * <charles@karney.com> and licensed under the MIT/X11 License.
 * For more information, see
 * http://geographiclib.sourceforge.net/
 **********************************************************************/

namespace NETGeographicLib
{
  /**
   * \brief .NET wrapper for GeographicLib::Geoid.
   *
   * This class allows .NET applications to access GeographicLib::Geoid.
   *
   * This class evaluated the height of one of the standard geoids, EGM84,
   * EGM96, or EGM2008 by bilinear or cubic interpolation into a rectangular
   * grid of data.  These geoid models are documented in
   * - EGM84:
   *   http://earth-info.nga.mil/GandG/wgs84/gravitymod/wgs84_180/wgs84_180.html
   * - EGM96:
   *   http://earth-info.nga.mil/GandG/wgs84/gravitymod/egm96/egm96.html
   * - EGM2008:
   *   http://earth-info.nga.mil/GandG/wgs84/gravitymod/egm2008
   *
   * The geoids are defined in terms of spherical harmonics.  However in order
   * to provide a quick and flexible method of evaluating the geoid heights,
   * this class evaluates the height by interpolation into a grid of
   * precomputed values.
   *
   * See \ref geoid for details of how to install the data sets, the data
   * format, estimates of the interpolation errors, and how to use caching.
   *
   * In addition to returning the geoid height, the gradient of the geoid can
   * be calculated.  The gradient is defined as the rate of change of the geoid
   * as a function of position on the ellipsoid.  This uses the parameters for
   * the WGS84 ellipsoid.  The gradient defined in terms of the interpolated
   * heights.  As a result of the way that the geoid data is stored, the
   * calculation of gradients can result in large quantization errors.  This is
   * particularly acute for fine grids, at high latitudes, and for the easterly
   * gradient.
   *
   * This class is typically \e not thread safe in that a single instantiation
   * cannot be safely used by multiple threads because of the way the object
   * reads the data set and because it maintains a single-cell cache.  If
   * multiple threads need to calculate geoid heights they should all construct
   * thread-local instantiations.  Alternatively, set the optional \e
   * threadsafe parameter to true in the constructor.  This causes the
   * constructor to read all the data into memory and to turn off the
   * single-cell caching which results in a Geoid object which \e is thread
   * safe.
   *
   * C# Example:
   * \include example-Geoid.cs
   * Managed C++ Example:
   * \include example-Geoid.cpp
   * Visual Basic Example:
   * \include example-Geoid.vb
   *
   * <B>INTERFACE DIFFERENCES:</B><BR>
   * The () operator has been replaced with Height method.
   *
   * The following functions are implemented as properties:
   * Description, DateTime, GeoidFile, GeoidName, GeoidDirectory,
   * Interpolation, MaxError, RMSError, Offset, Scale, ThreadSafe,
   * Cache, CacheWest, CacheEast, CacheNorth, CacheSouth, MajorRadius,
   * and Flattening.
   **********************************************************************/
    public ref class Geoid
    {
        private:
        // a pointer to the unmanaged GeographicLib::Geoid.
        const GeographicLib::Geoid* m_pGeoid;

        // the finalizer frees hthe unmanaged memory when the object is destroyed.
        !Geoid(void);
    public:
        /**
         * Flags indicating conversions between heights above the geoid and heights
         * above the ellipsoid.
         **********************************************************************/
        enum class ConvertFlag {
          /**
           * The multiplier for converting from heights above the geoid to heights
           * above the ellipsoid.
           **********************************************************************/
          ELLIPSOIDTOGEOID = -1,
          /**
           * No conversion.
           **********************************************************************/
          NONE = 0,
          /**
           * The multiplier for converting from heights above the ellipsoid to
           * heights above the geoid.
           **********************************************************************/
          GEOIDTOELLIPSOID = 1,
        };

        /** \name Setting up the geoid
         **********************************************************************/
        ///@{
        /**
         * Construct a geoid.
         *
         * @param[in] name the name of the geoid.
         * @param[in] path (optional) directory for data file.
         * @param[in] cubic (optional) interpolation method; false means bilinear,
         *   true (the default) means cubic.
         * @param[in] threadsafe (optional), if true, construct a thread safe
         *   object.  The default is false
         * @exception GeographicErr if the data file cannot be found, is
         *   unreadable, or is corrupt.
         * @exception GeographicErr if \e threadsafe is true but the memory
         *   necessary for caching the data can't be allocated.
         *
         * The data file is formed by appending ".pgm" to the name.  If \e path is
         * specified (and is non-empty), then the file is loaded from directory, \e
         * path.  Otherwise the path is given by DefaultGeoidPath().  If the \e
         * threadsafe parameter is true, the data set is read into memory, the data
         * file is closed, and single-cell caching is turned off; this results in a
         * Geoid object which \e is thread safe.
         **********************************************************************/
        Geoid(System::String^ name, System::String^ path,
                       bool cubic, bool threadsafe);
        /**
         * The destructor calls the finalizer.
         **********************************************************************/
        ~Geoid()
        { this->!Geoid(); }

        /**
         * Set up a cache.
         *
         * @param[in] south latitude (degrees) of the south edge of the cached area.
         * @param[in] west longitude (degrees) of the west edge of the cached area.
         * @param[in] north latitude (degrees) of the north edge of the cached area.
         * @param[in] east longitude (degrees) of the east edge of the cached area.
         * @exception GeographicErr if the memory necessary for caching the data
         *   can't be allocated (in this case, you will have no cache and can try
         *   again with a smaller area).
         * @exception GeographicErr if there's a problem reading the data.
         * @exception GeographicErr if this is called on a threadsafe Geoid.
         *
         * Cache the data for the specified "rectangular" area bounded by the
         * parallels \e south and \e north and the meridians \e west and \e east.
         * \e east is always interpreted as being east of \e west, if necessary by
         * adding 360&deg; to its value.  \e south and \e north should be in
         * the range [&minus;90&deg;, 90&deg;]; \e west and \e east should
         * be in the range [&minus;540&deg;, 540&deg;).
         **********************************************************************/
        void CacheArea(double south, double west, double north, double east);

        /**
         * Cache all the data.
         *
         * @exception GeographicErr if the memory necessary for caching the data
         *   can't be allocated (in this case, you will have no cache and can try
         *   again with a smaller area).
         * @exception GeographicErr if there's a problem reading the data.
         * @exception GeographicErr if this is called on a threadsafe Geoid.
         *
         * On most computers, this is fast for data sets with grid resolution of 5'
         * or coarser.  For a 1' grid, the required RAM is 450MB; a 2.5' grid needs
         * 72MB; and a 5' grid needs 18MB.
         **********************************************************************/
        void CacheAll();

        /**
         * Clear the cache.  This never throws an error.  (This does nothing with a
         * thread safe Geoid.)
         **********************************************************************/
        void CacheClear();

        ///@}

        /** \name Compute geoid heights
         **********************************************************************/
        ///@{
        /**
         * Compute the geoid height at a point
         *
         * @param[in] lat latitude of the point (degrees).
         * @param[in] lon longitude of the point (degrees).
         * @exception GeographicErr if there's a problem reading the data; this
         *   never happens if (\e lat, \e lon) is within a successfully cached area.
         * @return geoid height (meters).
         *
         * The latitude should be in [&minus;90&deg;, 90&deg;] and
         * longitude should be in [&minus;540&deg;, 540&deg;).
         **********************************************************************/
        double Height(double lat, double lon);

        /**
         * Compute the geoid height and gradient at a point
         *
         * @param[in] lat latitude of the point (degrees).
         * @param[in] lon longitude of the point (degrees).
         * @param[out] gradn northerly gradient (dimensionless).
         * @param[out] grade easterly gradient (dimensionless).
         * @exception GeographicErr if there's a problem reading the data; this
         *   never happens if (\e lat, \e lon) is within a successfully cached area.
         * @return geoid height (meters).
         *
         * The latitude should be in [&minus;90&deg;, 90&deg;] and
         * longitude should be in [&minus;540&deg;, 540&deg;).  As a result
         * of the way that the geoid data is stored, the calculation of gradients
         * can result in large quantization errors.  This is particularly acute for
         * fine grids, at high latitudes, and for the easterly gradient.  If you
         * need to compute the direction of the acceleration due to gravity
         * accurately, you should use GravityModel::Gravity.
         **********************************************************************/
        double Height(double lat, double lon,
            [System::Runtime::InteropServices::Out] double% gradn,
            [System::Runtime::InteropServices::Out] double% grade);

        /**
         * Convert a height above the geoid to a height above the ellipsoid and
         * vice versa.
         *
         * @param[in] lat latitude of the point (degrees).
         * @param[in] lon longitude of the point (degrees).
         * @param[in] h height of the point (degrees).
         * @param[in] d a Geoid::convertflag specifying the direction of the
         *   conversion; Geoid::GEOIDTOELLIPSOID means convert a height above the
         *   geoid to a height above the ellipsoid; Geoid::ELLIPSOIDTOGEOID means
         *   convert a height above the ellipsoid to a height above the geoid.
         * @exception GeographicErr if there's a problem reading the data; this
         *   never happens if (\e lat, \e lon) is within a successfully cached area.
         * @return converted height (meters).
         **********************************************************************/
        double ConvertHeight(double lat, double lon, double h,
                                 ConvertFlag d);

        ///@}

        /** \name Inspector functions
         **********************************************************************/
        ///@{
        /**
         * @return geoid description, if available, in the data file; if
         *   absent, return "NONE".
         **********************************************************************/
        property System::String^ Description { System::String^ get(); }

        /**
         * @return date of the data file; if absent, return "UNKNOWN".
         **********************************************************************/
        property System::String^ DateTime { System::String^ get(); }

        /**
         * @return full file name used to load the geoid data.
         **********************************************************************/
        property System::String^ GeoidFile { System::String^ get(); }

        /**
         * @return "name" used to load the geoid data (from the first argument of
         *   the constructor).
         **********************************************************************/
        property System::String^ GeoidName { System::String^ get(); }

        /**
         * @return directory used to load the geoid data.
         **********************************************************************/
        property System::String^ GeoidDirectory { System::String^ get(); }

        /**
         * @return interpolation method ("cubic" or "bilinear").
         **********************************************************************/
        property System::String^ Interpolation { System::String^ get(); }

        /**
         * @return estimate of the maximum interpolation and quantization error
         *   (meters).
         *
         * This relies on the value being stored in the data file.  If the value is
         * absent, return &minus;1.
         **********************************************************************/
        property double MaxError { double get(); }

        /**
         * @return estimate of the RMS interpolation and quantization error
         *   (meters).
         *
         * This relies on the value being stored in the data file.  If the value is
         * absent, return &minus;1.
         **********************************************************************/
        property double RMSError { double get(); }

        /**
         * @return offset (meters).
         *
         * This in used in converting from the pixel values in the data file to
         * geoid heights.
         **********************************************************************/
        property double Offset { double get(); }

        /**
         * @return scale (meters).
         *
         * This in used in converting from the pixel values in the data file to
         * geoid heights.
         **********************************************************************/
        property double Scale { double get(); }

        /**
         * @return true if the object is constructed to be thread safe.
         **********************************************************************/
        property bool ThreadSafe { bool get(); }

        /**
         * @return true if a data cache is active.
         **********************************************************************/
        property bool Cache { bool get(); }

        /**
         * @return west edge of the cached area; the cache includes this edge.
         **********************************************************************/
        property double CacheWest { double get(); }

        /**
         * @return east edge of the cached area; the cache excludes this edge.
         **********************************************************************/
        property double CacheEast { double get(); }

        /**
         * @return north edge of the cached area; the cache includes this edge.
         **********************************************************************/
        property double CacheNorth { double get(); }

        /**
         * @return south edge of the cached area; the cache excludes this edge
         *   unless it's the south pole.
         **********************************************************************/
        property double CacheSouth { double get(); }

        /**
         * @return \e a the equatorial radius of the WGS84 ellipsoid (meters).
         *
         * (The WGS84 value is returned because the supported geoid models are all
         * based on this ellipsoid.)
         **********************************************************************/
        property double MajorRadius { double get(); }

        /**
         * @return \e f the flattening of the WGS84 ellipsoid.
         *
         * (The WGS84 value is returned because the supported geoid models are all
         * based on this ellipsoid.)
         **********************************************************************/
        property double Flattening { double get(); }
        ///@}

        /**
         * @return the default path for geoid data files.
         *
         * This is the value of the environment variable
         * GEOGRAPHICLIB_GEOID_PATH, if set; otherwise, it is
         * $GEOGRAPHICLIB_DATA/geoids if the environment variable
         * GEOGRAPHICLIB_DATA is set; otherwise, it is a compile-time default
         * (/usr/local/share/GeographicLib/geoids on non-Windows systems and
         * C:/ProgramData/GeographicLib/geoids on Windows systems).
         **********************************************************************/
        static System::String^ DefaultGeoidPath();

        /**
         * @return the default name for the geoid.
         *
         * This is the value of the environment variable
         * GEOGRAPHICLIB_GEOID_NAME, if set, otherwise, it is "egm96-5".  The
         * Geoid class does not use this function; it is just provided as a
         * convenience for a calling program when constructing a Geoid object.
         **********************************************************************/
        static System::String^ DefaultGeoidName();
    };
} // namespace NETGeographicLib