1 /**
2  * \file NETGeographicLib/LambertConformalConic.cpp
3  * \brief Implementation for NETGeographicLib::LambertConformalConic 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/LambertConformalConic.hpp"
13 #include "LambertConformalConic.h"
14 #include "NETGeographicLib.h"
15 
16 using namespace NETGeographicLib;
17 
18 const char BADALLOC[] = "Failed to allocte memory for a GeographicLib::LambertConformalConic";
19 
20 //*****************************************************************************
21 LambertConformalConic::!LambertConformalConic(void)
22 {
23     if ( m_pLambertConformalConic != NULL )
24     {
25         delete m_pLambertConformalConic;
26         m_pLambertConformalConic = NULL;
27     }
28 }
29 
30 //*****************************************************************************
LambertConformalConic(double a,double f,double stdlat,double k0)31 LambertConformalConic::LambertConformalConic(double a, double f, double stdlat,
32                                              double k0)
33 {
34     try
35     {
36         m_pLambertConformalConic =
37             new GeographicLib::LambertConformalConic( a, f, stdlat, k0 );
38     }
39     catch ( std::bad_alloc )
40     {
41         throw gcnew GeographicErr( BADALLOC );
42     }
43     catch ( const std::exception& err )
44     {
45         throw gcnew GeographicErr( err.what() );
46     }
47 }
48 
49 //*****************************************************************************
LambertConformalConic(double a,double f,double stdlat1,double stdlat2,double k1)50 LambertConformalConic::LambertConformalConic(double a, double f,
51     double stdlat1, double stdlat2, double k1)
52 {
53     try
54     {
55         m_pLambertConformalConic =
56             new GeographicLib::LambertConformalConic( a, f, stdlat1, stdlat2, k1 );
57     }
58     catch ( std::bad_alloc )
59     {
60         throw gcnew GeographicErr( BADALLOC );
61     }
62     catch ( const std::exception& err )
63     {
64         throw gcnew GeographicErr( err.what() );
65     }
66 }
67 
68 //*****************************************************************************
LambertConformalConic(double a,double f,double sinlat1,double coslat1,double sinlat2,double coslat2,double k1)69 LambertConformalConic::LambertConformalConic(double a, double f,
70                         double sinlat1, double coslat1,
71                         double sinlat2, double coslat2,
72                         double k1)
73 {
74     try
75     {
76         m_pLambertConformalConic =
77             new GeographicLib::LambertConformalConic( a, f, sinlat1, coslat1,
78                         sinlat2, coslat2, k1 );
79     }
80     catch ( std::bad_alloc )
81     {
82         throw gcnew GeographicErr( BADALLOC );
83     }
84     catch ( const std::exception& err )
85     {
86         throw gcnew GeographicErr( err.what() );
87     }
88 }
89 
90 //*****************************************************************************
LambertConformalConic()91 LambertConformalConic::LambertConformalConic()
92 {
93     try
94     {
95         m_pLambertConformalConic = new GeographicLib::LambertConformalConic(
96             GeographicLib::LambertConformalConic::Mercator() );
97     }
98     catch ( std::bad_alloc )
99     {
100         throw gcnew GeographicErr( BADALLOC );
101     }
102 }
103 
104 //*****************************************************************************
SetScale(double lat,double k)105 void LambertConformalConic::SetScale(double lat, double k)
106 {
107     try
108     {
109         m_pLambertConformalConic->SetScale( lat, k );
110     }
111     catch ( std::exception err )
112     {
113         throw gcnew GeographicErr( err.what() );
114     }
115 }
116 
117 //*****************************************************************************
118 void LambertConformalConic::Forward(double lon0, double lat, double lon,
119                 [System::Runtime::InteropServices::Out] double% x,
120                 [System::Runtime::InteropServices::Out] double% y,
121                 [System::Runtime::InteropServices::Out] double% gamma,
122                 [System::Runtime::InteropServices::Out] double% k)
123 {
124     double lx, ly, lgamma, lk;
125     m_pLambertConformalConic->Forward( lon0, lat, lon, lx, ly, lgamma, lk );
126     x = lx;
127     y = ly;
128     gamma = lgamma;
129     k = lk;
130 }
131 
132 //*****************************************************************************
133 void LambertConformalConic::Reverse(double lon0, double x, double y,
134                 [System::Runtime::InteropServices::Out] double% lat,
135                 [System::Runtime::InteropServices::Out] double% lon,
136                 [System::Runtime::InteropServices::Out] double% gamma,
137                 [System::Runtime::InteropServices::Out] double% k)
138 {
139     double llat, llon, lgamma, lk;
140     m_pLambertConformalConic->Reverse( lon0, x, y, llat, llon, lgamma, lk );
141     lat = llat;
142     lon = llon;
143     gamma = lgamma;
144     k = lk;
145 }
146 
147 //*****************************************************************************
148 void LambertConformalConic::Forward(double lon0, double lat, double lon,
149                 [System::Runtime::InteropServices::Out] double% x,
150                 [System::Runtime::InteropServices::Out] double% y)
151 {
152     double lx, ly;
153     m_pLambertConformalConic->Forward( lon0, lat, lon, lx, ly );
154     x = lx;
155     y = ly;
156 }
157 
158 //*****************************************************************************
159 void LambertConformalConic::Reverse(double lon0, double x, double y,
160                 [System::Runtime::InteropServices::Out] double% lat,
161                 [System::Runtime::InteropServices::Out] double% lon)
162 {
163     double llat, llon;
164     m_pLambertConformalConic->Reverse( lon0, x, y, llat, llon );
165     lat = llat;
166     lon = llon;
167 }
168 
169 //*****************************************************************************
get()170 double LambertConformalConic::EquatorialRadius::get()
171 { return m_pLambertConformalConic->EquatorialRadius(); }
172 
173 //*****************************************************************************
get()174 double LambertConformalConic::Flattening::get()
175 { return m_pLambertConformalConic->Flattening(); }
176 
177 //*****************************************************************************
get()178 double LambertConformalConic::OriginLatitude::get()
179 { return m_pLambertConformalConic->OriginLatitude(); }
180 
181 //*****************************************************************************
get()182 double LambertConformalConic::CentralScale::get()
183 { return m_pLambertConformalConic->CentralScale(); }
184