File: GeoCoords.cpp

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 (243 lines) | stat: -rw-r--r-- 8,387 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
/**
 * \file NETGeographicLib/GeoCoords.cpp
 * \brief Implementation for NETGeographicLib::GeoCoords 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/
 **********************************************************************/
#include "stdafx.h"
#include "GeographicLib/GeoCoords.hpp"
#include "GeoCoords.h"
#include "UTMUPS.h"
#include "NETGeographicLib.h"

using namespace NETGeographicLib;

const char BADALLOC[] = "Failed to allocate memory for a GeographicLib::GeoCoords";

//*****************************************************************************
GeoCoords::!GeoCoords(void)
{
    if ( m_pGeoCoords != NULL )
    {
        delete m_pGeoCoords;
        m_pGeoCoords = NULL;
    }
}

//*****************************************************************************
GeoCoords::GeoCoords()
{
    try
    {
        m_pGeoCoords = new GeographicLib::GeoCoords();
    }
    catch ( std::bad_alloc )
    {
        throw gcnew GeographicErr( BADALLOC );
    }
}

//*****************************************************************************
GeoCoords::GeoCoords(System::String^ s, bool centerp, bool swaplatlong )
{
    try
    {
        m_pGeoCoords = new GeographicLib::GeoCoords(StringConvert::ManagedToUnmanaged(s), centerp, swaplatlong);
    }
    catch ( std::bad_alloc )
    {
        throw gcnew GeographicErr( BADALLOC );
    }
    catch ( const std::exception& err )
    {
        throw gcnew GeographicErr( err.what() );
    }
}

//*****************************************************************************
GeoCoords::GeoCoords(double latitude, double longitude, int zone )
{
    try
    {
        m_pGeoCoords = new GeographicLib::GeoCoords(latitude, longitude, zone);
    }
    catch ( std::bad_alloc )
    {
        throw gcnew GeographicErr( BADALLOC );
    }
    catch ( const std::exception& err )
    {
        throw gcnew GeographicErr( err.what() );
    }
}

//*****************************************************************************
GeoCoords::GeoCoords(int zone, bool northp, double easting, double northing)
{
    try
    {
        m_pGeoCoords = new GeographicLib::GeoCoords(zone, northp, easting, northing);
    }
    catch ( std::bad_alloc )
    {
        throw gcnew GeographicErr( BADALLOC );
    }
    catch ( const std::exception& err )
    {
        throw gcnew GeographicErr( err.what() );
    }
}

//*****************************************************************************
void GeoCoords::Reset( System::String^ s, bool centerp, bool swaplatlong )
{
    try
    {
        m_pGeoCoords->Reset(StringConvert::ManagedToUnmanaged(s), centerp, swaplatlong);
    }
    catch ( const std::exception& err )
    {
        throw gcnew GeographicErr( err.what() );
    }
}

//*****************************************************************************
void GeoCoords::Reset(double latitude, double longitude, int zone)
{
    try
    {
        m_pGeoCoords->Reset(latitude, longitude, zone);
    }
    catch ( const std::exception& err )
    {
        throw gcnew GeographicErr( err.what() );
    }
}

//*****************************************************************************
void GeoCoords::Reset(int zone, bool northp, double easting, double northing)
{
    try
    {
        m_pGeoCoords->Reset(zone, northp, easting, northing);
    }
    catch ( const std::exception& err )
    {
        throw gcnew GeographicErr( err.what() );
    }
}

//*****************************************************************************
void GeoCoords::AltZone::set( int zone )
{
    try
    {
        m_pGeoCoords->SetAltZone(zone);
    }
    catch ( GeographicLib::GeographicErr err )
    {
        throw gcnew GeographicErr( err.what() );
    }
}

//*****************************************************************************
int GeoCoords::AltZone::get() { return m_pGeoCoords->AltZone(); }

//*****************************************************************************
double GeoCoords::Latitude::get() { return m_pGeoCoords->Latitude(); }

//*****************************************************************************
double GeoCoords::Longitude::get() { return m_pGeoCoords->Longitude(); }

//*****************************************************************************
double GeoCoords::Easting::get() { return m_pGeoCoords->Easting(); }

//*****************************************************************************
double GeoCoords::Northing::get() { return m_pGeoCoords->Northing(); }

//*****************************************************************************
double GeoCoords::Convergence::get() { return m_pGeoCoords->Convergence(); }

//*****************************************************************************
double GeoCoords::Scale::get() { return m_pGeoCoords->Scale(); }

//*****************************************************************************
bool GeoCoords::Northp::get() { return m_pGeoCoords->Northp(); }

//*****************************************************************************
char GeoCoords::Hemisphere::get() { return m_pGeoCoords->Hemisphere(); }

//*****************************************************************************
int GeoCoords::Zone::get() { return m_pGeoCoords->Zone(); }

//*****************************************************************************
double GeoCoords::AltEasting::get() { return m_pGeoCoords->AltEasting(); }

//*****************************************************************************
double GeoCoords::AltNorthing::get() { return m_pGeoCoords->AltNorthing(); }

//*****************************************************************************
double GeoCoords::AltConvergence::get()
{ return m_pGeoCoords->AltConvergence(); }

//*****************************************************************************
double GeoCoords::AltScale::get() { return m_pGeoCoords->AltScale(); }

//*****************************************************************************
double GeoCoords::MajorRadius::get() { return UTMUPS::MajorRadius(); }

//*****************************************************************************
double GeoCoords::Flattening::get() { return UTMUPS::Flattening(); }

//*****************************************************************************
System::String^ GeoCoords::GeoRepresentation(int prec, bool swaplatlong )
{
    return gcnew System::String( m_pGeoCoords->GeoRepresentation(prec, swaplatlong).c_str() );
}

//*****************************************************************************
System::String^ GeoCoords::DMSRepresentation(int prec, bool swaplatlong,
                                char dmssep )
{
    return gcnew System::String( m_pGeoCoords->DMSRepresentation(prec, swaplatlong, dmssep).c_str() );
}

//*****************************************************************************
System::String^ GeoCoords::MGRSRepresentation(int prec)
{
    return gcnew System::String( m_pGeoCoords->MGRSRepresentation(prec).c_str() );
}

//*****************************************************************************
System::String^ GeoCoords::UTMUPSRepresentation(int prec, bool abbrev)
{
    return gcnew System::String( m_pGeoCoords->UTMUPSRepresentation(prec, abbrev).c_str() );
}

//*****************************************************************************
System::String^ GeoCoords::UTMUPSRepresentation(bool northp, int prec, bool abbrev)
{
    return gcnew System::String( m_pGeoCoords->UTMUPSRepresentation(northp, prec, abbrev).c_str() );
}

//*****************************************************************************
System::String^ GeoCoords::AltMGRSRepresentation(int prec)
{
    return gcnew System::String( m_pGeoCoords->AltMGRSRepresentation(prec).c_str() );
}

//*****************************************************************************
System::String^ GeoCoords::AltUTMUPSRepresentation(int prec, bool abbrev)
{
    return gcnew System::String( m_pGeoCoords->AltUTMUPSRepresentation(prec, abbrev).c_str() );
}

//*****************************************************************************
System::String^ GeoCoords::AltUTMUPSRepresentation(bool northp, int prec, bool abbrev)
{
    return gcnew System::String( m_pGeoCoords->AltUTMUPSRepresentation(northp, prec, abbrev).c_str() );
}