NETGeographicLib  1.48
Public Types | Static Public Member Functions | List of all members
NETGeographicLib::Geoid Class Reference

.NET wrapper for GeographicLib::Geoid. More...

#include <NETGeographicLib/Geoid.h>

Public Types

enum  ConvertFlag { ConvertFlag::ELLIPSOIDTOGEOID = -1, ConvertFlag::NONE = 0, ConvertFlag::GEOIDTOELLIPSOID = 1 }
 

Public Member Functions

Setting up the geoid
 Geoid (System::String^ name, System::String^ path, bool cubic, bool threadsafe)
 
 ~Geoid ()
 
void CacheArea (double south, double west, double north, double east)
 
void CacheAll ()
 
void CacheClear ()
 
Compute geoid heights
double Height (double lat, double lon)
 
double ConvertHeight (double lat, double lon, double h, ConvertFlag d)
 

Static Public Member Functions

static System::String ^ DefaultGeoidPath ()
 
static System::String ^ DefaultGeoidName ()
 

Properties

Inspector functions
System::String^ Description [get]
 
System::String^ DateTime [get]
 
System::String^ GeoidFile [get]
 
System::String^ GeoidName [get]
 
System::String^ GeoidDirectory [get]
 
System::String^ Interpolation [get]
 
double MaxError [get]
 
double RMSError [get]
 
double Offset [get]
 
double Scale [get]
 
bool ThreadSafe [get]
 
bool Cache [get]
 
double CacheWest [get]
 
double CacheEast [get]
 
double CacheNorth [get]
 
double CacheSouth [get]
 
double MajorRadius [get]
 
double Flattening [get]
 

Detailed Description

.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

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.

The geoid height, N, can be used to convert a height above the ellipsoid, h, to the corresponding height above the geoid (roughly the height above mean sea level), H, using the relations

   h = N + H;   H = −N + h.

See Geoid height for details of how to install the data sets, the data format, estimates of the interpolation errors, and how to use caching.

This class is typically 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 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 is thread safe.

C# Example:

using System;
namespace example_Geoid
{
class Program
{
static void Main(string[] args)
{
try {
Geoid egm96 = new Geoid("egm96-5", "", true, false);
// Convert height above egm96 to height above the ellipsoid
double lat = 42, lon = -75, height_above_geoid = 20;
double
geoid_height = egm96.Height(lat, lon),
height_above_ellipsoid = (height_above_geoid +
(double)Geoid.ConvertFlag.GEOIDTOELLIPSOID * geoid_height);
Console.WriteLine(height_above_ellipsoid);
}
catch (GeographicErr e) {
Console.WriteLine(String.Format("Caught exception: {0}", e.Message));
}
}
}
}

Managed C++ Example:

using namespace System;
using namespace NETGeographicLib;
int main(array<System::String ^> ^/*args*/)
{
try {
Geoid^ egm96 = gcnew Geoid("egm96-5", "", true, false);
// Convert height above egm96 to height above the ellipsoid
double lat = 42, lon = -75, height_above_geoid = 20;
double
geoid_height = egm96->Height(lat, lon),
height_above_ellipsoid = (height_above_geoid +
(double)Geoid::ConvertFlag::GEOIDTOELLIPSOID * geoid_height);
Console::WriteLine(height_above_ellipsoid);
}
catch (GeographicErr^ e) {
Console::WriteLine(String::Format("Caught exception: {0}", e->Message));
return -1;
}
return 0;
}

Visual Basic Example:

Imports NETGeographicLib
Module example_Geoid
Sub Main()
Try
Dim egm96 As Geoid = New Geoid("egm96-5", "", True, False)
' Convert height above egm96 to height above the ellipsoid
Dim lat As Double = 42, lon = -75, height_above_geoid = 20
Dim geoid_height As Double = egm96.Height(lat, lon)
Dim height_above_ellipsoid As Double = (height_above_geoid +
CDbl(Geoid.ConvertFlag.GEOIDTOELLIPSOID) * geoid_height)
Console.WriteLine(height_above_ellipsoid)
Catch ex As GeographicErr
Console.WriteLine(String.Format("Caught exception: {0}", ex.Message))
End Try
End Sub
End Module

INTERFACE DIFFERENCES:
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.

Definition at line 71 of file Geoid.h.

Member Enumeration Documentation

◆ ConvertFlag

Flags indicating conversions between heights above the geoid and heights above the ellipsoid.

Enumerator
ELLIPSOIDTOGEOID 

The multiplier for converting from heights above the geoid to heights above the ellipsoid.

NONE 

No conversion.

GEOIDTOELLIPSOID 

The multiplier for converting from heights above the ellipsoid to heights above the geoid.

Definition at line 84 of file Geoid.h.

Constructor & Destructor Documentation

◆ Geoid()

NETGeographicLib::Geoid::Geoid ( System::String^  name,
System::String^  path,
bool  cubic,
bool  threadsafe 
)

Construct a geoid.

Parameters
[in]namethe name of the geoid.
[in]path(optional) directory for data file.
[in]cubic(optional) interpolation method; false means bilinear, true (the default) means cubic.
[in]threadsafe(optional), if true, construct a thread safe object. The default is false
Exceptions
GeographicErrif the data file cannot be found, is unreadable, or is corrupt.
GeographicErrif 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 path is specified (and is non-empty), then the file is loaded from directory, path. Otherwise the path is given by DefaultGeoidPath(). If the 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 is thread safe.

Referenced by ~Geoid().

◆ ~Geoid()

NETGeographicLib::Geoid::~Geoid ( )
inline

The destructor calls the finalizer.

Definition at line 130 of file Geoid.h.

References CacheAll(), CacheArea(), CacheClear(), ConvertHeight(), Geoid(), and Height().

Member Function Documentation

◆ CacheArea()

void NETGeographicLib::Geoid::CacheArea ( double  south,
double  west,
double  north,
double  east 
)

Set up a cache.

Parameters
[in]southlatitude (degrees) of the south edge of the cached area.
[in]westlongitude (degrees) of the west edge of the cached area.
[in]northlatitude (degrees) of the north edge of the cached area.
[in]eastlongitude (degrees) of the east edge of the cached area.
Exceptions
GeographicErrif 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).
GeographicErrif there's a problem reading the data.
GeographicErrif this is called on a threadsafe Geoid.

Cache the data for the specified "rectangular" area bounded by the parallels south and north and the meridians west and east. east is always interpreted as being east of west, if necessary by adding 360° to its value. south and north should be in the range [−90°, 90°].

Referenced by ~Geoid().

◆ CacheAll()

void NETGeographicLib::Geoid::CacheAll ( )

Cache all the data.

Exceptions
GeographicErrif 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).
GeographicErrif there's a problem reading the data.
GeographicErrif 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.

Referenced by ~Geoid().

◆ CacheClear()

void NETGeographicLib::Geoid::CacheClear ( )

Clear the cache. This never throws an error. (This does nothing with a thread safe Geoid.)

Referenced by ~Geoid().

◆ Height()

double NETGeographicLib::Geoid::Height ( double  lat,
double  lon 
)

Compute the geoid height at a point

Parameters
[in]latlatitude of the point (degrees).
[in]lonlongitude of the point (degrees).
Exceptions
GeographicErrif there's a problem reading the data; this never happens if (lat, lon) is within a successfully cached area.
Returns
geoid height (meters).

The latitude should be in [−90°, 90°].

Referenced by ~Geoid().

◆ ConvertHeight()

double NETGeographicLib::Geoid::ConvertHeight ( double  lat,
double  lon,
double  h,
ConvertFlag  d 
)

Convert a height above the geoid to a height above the ellipsoid and vice versa.

Parameters
[in]latlatitude of the point (degrees).
[in]lonlongitude of the point (degrees).
[in]hheight of the point (degrees).
[in]da 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.
Exceptions
GeographicErrif there's a problem reading the data; this never happens if (lat, lon) is within a successfully cached area.
Returns
converted height (meters).

Referenced by ~Geoid().

◆ DefaultGeoidPath()

static System::String ^ NETGeographicLib::Geoid::DefaultGeoidPath ( )
static
Returns
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).

◆ DefaultGeoidName()

static System::String ^ NETGeographicLib::Geoid::DefaultGeoidName ( )
static
Returns
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.

Property Documentation

◆ Description

System:: String^ NETGeographicLib::Geoid::Description
get
Returns
geoid description, if available, in the data file; if absent, return "NONE".

Definition at line 220 of file Geoid.h.

◆ DateTime

System:: String^ NETGeographicLib::Geoid::DateTime
get
Returns
date of the data file; if absent, return "UNKNOWN".

Definition at line 225 of file Geoid.h.

◆ GeoidFile

System:: String^ NETGeographicLib::Geoid::GeoidFile
get
Returns
full file name used to load the geoid data.

Definition at line 230 of file Geoid.h.

◆ GeoidName

System:: String^ NETGeographicLib::Geoid::GeoidName
get
Returns
"name" used to load the geoid data (from the first argument of the constructor).

Definition at line 236 of file Geoid.h.

◆ GeoidDirectory

System:: String^ NETGeographicLib::Geoid::GeoidDirectory
get
Returns
directory used to load the geoid data.

Definition at line 241 of file Geoid.h.

◆ Interpolation

System:: String^ NETGeographicLib::Geoid::Interpolation
get
Returns
interpolation method ("cubic" or "bilinear").

Definition at line 246 of file Geoid.h.

◆ MaxError

double NETGeographicLib::Geoid::MaxError
get
Returns
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 −1.

Definition at line 255 of file Geoid.h.

◆ RMSError

double NETGeographicLib::Geoid::RMSError
get
Returns
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 −1.

Definition at line 264 of file Geoid.h.

◆ Offset

double NETGeographicLib::Geoid::Offset
get
Returns
offset (meters).

This in used in converting from the pixel values in the data file to geoid heights.

Definition at line 272 of file Geoid.h.

◆ Scale

double NETGeographicLib::Geoid::Scale
get
Returns
scale (meters).

This in used in converting from the pixel values in the data file to geoid heights.

Definition at line 280 of file Geoid.h.

◆ ThreadSafe

bool NETGeographicLib::Geoid::ThreadSafe
get
Returns
true if the object is constructed to be thread safe.

Definition at line 285 of file Geoid.h.

◆ Cache

bool NETGeographicLib::Geoid::Cache
get
Returns
true if a data cache is active.

Definition at line 290 of file Geoid.h.

◆ CacheWest

double NETGeographicLib::Geoid::CacheWest
get
Returns
west edge of the cached area; the cache includes this edge.

Definition at line 295 of file Geoid.h.

◆ CacheEast

double NETGeographicLib::Geoid::CacheEast
get
Returns
east edge of the cached area; the cache excludes this edge.

Definition at line 300 of file Geoid.h.

◆ CacheNorth

double NETGeographicLib::Geoid::CacheNorth
get
Returns
north edge of the cached area; the cache includes this edge.

Definition at line 305 of file Geoid.h.

◆ CacheSouth

double NETGeographicLib::Geoid::CacheSouth
get
Returns
south edge of the cached area; the cache excludes this edge unless it's the south pole.

Definition at line 311 of file Geoid.h.

◆ MajorRadius

double NETGeographicLib::Geoid::MajorRadius
get
Returns
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.)

Definition at line 319 of file Geoid.h.

◆ Flattening

double NETGeographicLib::Geoid::Flattening
get
Returns
f the flattening of the WGS84 ellipsoid.

(The WGS84 value is returned because the supported geoid models are all based on this ellipsoid.)

Definition at line 327 of file Geoid.h.


The documentation for this class was generated from the following file: