1 /**
2  * \file NETGeographicLib/OSGB.cpp
3  * \brief Implementation for NETGeographicLib::OSGB class
4  *
5  * NETGeographicLib is copyright (c) Scott Heiman (2013)
6  * GeographicLib is Copyright (c) Charles Karney (2010-2012)
7  * <charles@karney.com> and licensed under the MIT/X11 License.
8  * For more information, see
9  * https://geographiclib.sourceforge.io/
10  **********************************************************************/
11 #include "stdafx.h"
12 #include "GeographicLib/OSGB.hpp"
13 #include "OSGB.h"
14 #include "NETGeographicLib.h"
15 
16 using namespace NETGeographicLib;
17 
18 //*****************************************************************************
19 void OSGB::Forward(double lat, double lon,
20                     [System::Runtime::InteropServices::Out] double% x,
21                     [System::Runtime::InteropServices::Out] double% y,
22                     [System::Runtime::InteropServices::Out] double% gamma,
23                     [System::Runtime::InteropServices::Out] double% k)
24 {
25     double lx, ly, lgamma, lk;
26     GeographicLib::OSGB::Forward( lat, lon, lx, ly, lgamma, lk );
27     x = lx;
28     y = ly;
29     gamma = lgamma;
30     k = lk;
31 }
32 
33 //*****************************************************************************
34 void OSGB::Reverse(double x, double y,
35                     [System::Runtime::InteropServices::Out] double% lat,
36                     [System::Runtime::InteropServices::Out] double% lon,
37                     [System::Runtime::InteropServices::Out] double% gamma,
38                     [System::Runtime::InteropServices::Out] double% k)
39 {
40     double llat, llon, lgamma, lk;
41     GeographicLib::OSGB::Reverse( x, y, llat, llon, lgamma, lk );
42     lat = llat;
43     lon = llon;
44     gamma = lgamma;
45     k = lk;
46 }
47 
48 //*****************************************************************************
49 void OSGB::Forward(double lat, double lon,
50     [System::Runtime::InteropServices::Out] double% x,
51     [System::Runtime::InteropServices::Out] double% y)
52 {
53     double lx, ly;
54     GeographicLib::OSGB::Forward( lat, lon, lx, ly );
55     x = lx;
56     y = ly;
57 }
58 
59 //*****************************************************************************
60 void OSGB::Reverse(double x, double y,
61     [System::Runtime::InteropServices::Out] double% lat,
62     [System::Runtime::InteropServices::Out] double% lon)
63 {
64     double llat, llon;
65     GeographicLib::OSGB::Reverse( x, y, llat, llon );
66     lat = llat;
67     lon = llon;
68 }
69 
70 //*****************************************************************************
71 void OSGB::GridReference(double x, double y, int prec,
72     [System::Runtime::InteropServices::Out] System::String^% gridref)
73 {
74     try
75     {
76         std::string lgridref;
77         GeographicLib::OSGB::GridReference( x, y, prec, lgridref );
78         gridref = gcnew System::String( lgridref.c_str() );
79     }
80     catch ( std::bad_alloc )
81     {
82         throw gcnew GeographicErr( "Memory allocation error in OSGB::GridReference" );
83     }
84     catch ( const std::exception& err )
85     {
86         throw gcnew GeographicErr( err.what() );
87     }
88 }
89 
90 //*****************************************************************************
91 void OSGB::GridReference(System::String^ gridref,
92                     [System::Runtime::InteropServices::Out] double% x,
93                     [System::Runtime::InteropServices::Out] double% y,
94                     [System::Runtime::InteropServices::Out] int% prec,
95                     bool centerp )
96 {
97     try
98     {
99         double lx, ly;
100         int lprec;
101         GeographicLib::OSGB::GridReference(
102             StringConvert::ManagedToUnmanaged( gridref ),
103             lx, ly, lprec, centerp );
104         x = lx;
105         y = ly;
106         prec = lprec;
107     }
108     catch ( const std::exception& err )
109     {
110         throw gcnew GeographicErr( err.what() );
111     }
112 }
113 
114 //*****************************************************************************
EquatorialRadius()115 double OSGB::EquatorialRadius() { return GeographicLib::OSGB::EquatorialRadius(); }
116 
117 //*****************************************************************************
Flattening()118 double OSGB::Flattening() { return GeographicLib::OSGB::Flattening(); }
119 
120 //*****************************************************************************
CentralScale()121 double OSGB::CentralScale() { return GeographicLib::OSGB::CentralScale(); }
122 
123 //*****************************************************************************
OriginLatitude()124 double OSGB::OriginLatitude() { return GeographicLib::OSGB::OriginLatitude(); }
125 
126 //*****************************************************************************
OriginLongitude()127 double OSGB::OriginLongitude()
128 { return GeographicLib::OSGB::OriginLongitude(); }
129 
130 //*****************************************************************************
FalseNorthing()131 double OSGB::FalseNorthing() { return GeographicLib::OSGB::FalseNorthing(); }
132 
133 //*****************************************************************************
FalseEasting()134 double OSGB::FalseEasting() { return GeographicLib::OSGB::FalseEasting(); }
135