geographiclib 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +7 -0
  2. data/AUTHORS +12 -0
  3. data/LICENSE +24 -0
  4. data/ext/geographiclib/Accumulator.cpp +23 -0
  5. data/ext/geographiclib/AlbersEqualArea.cpp +445 -0
  6. data/ext/geographiclib/AzimuthalEquidistant.cpp +41 -0
  7. data/ext/geographiclib/CassiniSoldner.cpp +89 -0
  8. data/ext/geographiclib/CircularEngine.cpp +96 -0
  9. data/ext/geographiclib/DMS.cpp +381 -0
  10. data/ext/geographiclib/Ellipsoid.cpp +125 -0
  11. data/ext/geographiclib/EllipticFunction.cpp +512 -0
  12. data/ext/geographiclib/GARS.cpp +122 -0
  13. data/ext/geographiclib/GeoCoords.cpp +175 -0
  14. data/ext/geographiclib/Geocentric.cpp +172 -0
  15. data/ext/geographiclib/Geodesic.cpp +1908 -0
  16. data/ext/geographiclib/GeodesicExact.cpp +927 -0
  17. data/ext/geographiclib/GeodesicExactC4.cpp +7879 -0
  18. data/ext/geographiclib/GeodesicLine.cpp +321 -0
  19. data/ext/geographiclib/GeodesicLineExact.cpp +289 -0
  20. data/ext/geographiclib/GeographicLib/Accumulator.hpp +184 -0
  21. data/ext/geographiclib/GeographicLib/AlbersEqualArea.hpp +312 -0
  22. data/ext/geographiclib/GeographicLib/AzimuthalEquidistant.hpp +139 -0
  23. data/ext/geographiclib/GeographicLib/CassiniSoldner.hpp +204 -0
  24. data/ext/geographiclib/GeographicLib/CircularEngine.hpp +195 -0
  25. data/ext/geographiclib/GeographicLib/Config.h +12 -0
  26. data/ext/geographiclib/GeographicLib/Constants.hpp +387 -0
  27. data/ext/geographiclib/GeographicLib/DMS.hpp +370 -0
  28. data/ext/geographiclib/GeographicLib/Ellipsoid.hpp +534 -0
  29. data/ext/geographiclib/GeographicLib/EllipticFunction.hpp +692 -0
  30. data/ext/geographiclib/GeographicLib/GARS.hpp +143 -0
  31. data/ext/geographiclib/GeographicLib/GeoCoords.hpp +544 -0
  32. data/ext/geographiclib/GeographicLib/Geocentric.hpp +267 -0
  33. data/ext/geographiclib/GeographicLib/Geodesic.hpp +970 -0
  34. data/ext/geographiclib/GeographicLib/GeodesicExact.hpp +862 -0
  35. data/ext/geographiclib/GeographicLib/GeodesicLine.hpp +701 -0
  36. data/ext/geographiclib/GeographicLib/GeodesicLineExact.hpp +667 -0
  37. data/ext/geographiclib/GeographicLib/Geohash.hpp +180 -0
  38. data/ext/geographiclib/GeographicLib/Geoid.hpp +472 -0
  39. data/ext/geographiclib/GeographicLib/Georef.hpp +160 -0
  40. data/ext/geographiclib/GeographicLib/Gnomonic.hpp +206 -0
  41. data/ext/geographiclib/GeographicLib/GravityCircle.hpp +301 -0
  42. data/ext/geographiclib/GeographicLib/GravityModel.hpp +520 -0
  43. data/ext/geographiclib/GeographicLib/LambertConformalConic.hpp +313 -0
  44. data/ext/geographiclib/GeographicLib/LocalCartesian.hpp +236 -0
  45. data/ext/geographiclib/GeographicLib/MGRS.hpp +355 -0
  46. data/ext/geographiclib/GeographicLib/MagneticCircle.hpp +178 -0
  47. data/ext/geographiclib/GeographicLib/MagneticModel.hpp +347 -0
  48. data/ext/geographiclib/GeographicLib/Math.hpp +920 -0
  49. data/ext/geographiclib/GeographicLib/NormalGravity.hpp +350 -0
  50. data/ext/geographiclib/GeographicLib/OSGB.hpp +249 -0
  51. data/ext/geographiclib/GeographicLib/PolarStereographic.hpp +150 -0
  52. data/ext/geographiclib/GeographicLib/PolygonArea.hpp +288 -0
  53. data/ext/geographiclib/GeographicLib/Rhumb.hpp +589 -0
  54. data/ext/geographiclib/GeographicLib/SphericalEngine.hpp +376 -0
  55. data/ext/geographiclib/GeographicLib/SphericalHarmonic.hpp +354 -0
  56. data/ext/geographiclib/GeographicLib/SphericalHarmonic1.hpp +281 -0
  57. data/ext/geographiclib/GeographicLib/SphericalHarmonic2.hpp +315 -0
  58. data/ext/geographiclib/GeographicLib/TransverseMercator.hpp +196 -0
  59. data/ext/geographiclib/GeographicLib/TransverseMercatorExact.hpp +254 -0
  60. data/ext/geographiclib/GeographicLib/UTMUPS.hpp +421 -0
  61. data/ext/geographiclib/GeographicLib/Utility.hpp +612 -0
  62. data/ext/geographiclib/Geohash.cpp +102 -0
  63. data/ext/geographiclib/Geoid.cpp +509 -0
  64. data/ext/geographiclib/Georef.cpp +135 -0
  65. data/ext/geographiclib/Gnomonic.cpp +85 -0
  66. data/ext/geographiclib/GravityCircle.cpp +129 -0
  67. data/ext/geographiclib/GravityModel.cpp +360 -0
  68. data/ext/geographiclib/LambertConformalConic.cpp +456 -0
  69. data/ext/geographiclib/LocalCartesian.cpp +62 -0
  70. data/ext/geographiclib/MGRS.cpp +461 -0
  71. data/ext/geographiclib/MagneticCircle.cpp +52 -0
  72. data/ext/geographiclib/MagneticModel.cpp +269 -0
  73. data/ext/geographiclib/Math.cpp +63 -0
  74. data/ext/geographiclib/NormalGravity.cpp +262 -0
  75. data/ext/geographiclib/OSGB.cpp +167 -0
  76. data/ext/geographiclib/PolarStereographic.cpp +108 -0
  77. data/ext/geographiclib/PolygonArea.cpp +204 -0
  78. data/ext/geographiclib/Rhumb.cpp +383 -0
  79. data/ext/geographiclib/SphericalEngine.cpp +477 -0
  80. data/ext/geographiclib/TransverseMercator.cpp +603 -0
  81. data/ext/geographiclib/TransverseMercatorExact.cpp +464 -0
  82. data/ext/geographiclib/UTMUPS.cpp +296 -0
  83. data/ext/geographiclib/Utility.cpp +61 -0
  84. data/ext/geographiclib/extconf.rb +3 -0
  85. data/ext/geographiclib/geographiclib.cpp +62 -0
  86. data/lib/geographiclib.rb +20 -0
  87. metadata +140 -0
@@ -0,0 +1,143 @@
1
+ /**
2
+ * \file GARS.hpp
3
+ * \brief Header for GeographicLib::GARS class
4
+ *
5
+ * Copyright (c) Charles Karney (2015) <charles@karney.com> and licensed under
6
+ * the MIT/X11 License. For more information, see
7
+ * http://geographiclib.sourceforge.net/
8
+ **********************************************************************/
9
+
10
+ #if !defined(GEOGRAPHICLIB_GARS_HPP)
11
+ #define GEOGRAPHICLIB_GARS_HPP 1
12
+
13
+ #include <GeographicLib/Constants.hpp>
14
+
15
+ #if defined(_MSC_VER)
16
+ // Squelch warnings about dll vs string
17
+ # pragma warning (push)
18
+ # pragma warning (disable: 4251)
19
+ #endif
20
+
21
+ namespace GeographicLib {
22
+
23
+ /**
24
+ * \brief Conversions for the Global Area Reference System (GARS)
25
+ *
26
+ * The Global Area Reference System is described in
27
+ * - https://en.wikipedia.org/wiki/Global_Area_Reference_System
28
+ * - http://earth-info.nga.mil/GandG/coordsys/grids/gars.html
29
+ * .
30
+ * It provides a compact string representation of a geographic area
31
+ * (expressed as latitude and longitude). The classes Georef and Geohash
32
+ * implement similar compact representations.
33
+ *
34
+ * Example of use:
35
+ * \include example-GARS.cpp
36
+ **********************************************************************/
37
+
38
+ class GEOGRAPHICLIB_EXPORT GARS {
39
+ private:
40
+ typedef Math::real real;
41
+ static const std::string digits_;
42
+ static const std::string letters_;
43
+ enum {
44
+ lonorig_ = -180, // Origin for longitude
45
+ latorig_ = -90, // Origin for latitude
46
+ baselon_ = 10, // Base for longitude tiles
47
+ baselat_ = 24, // Base for latitude tiles
48
+ lonlen_ = 3,
49
+ latlen_ = 2,
50
+ baselen_ = lonlen_ + latlen_,
51
+ mult1_ = 2, // base precision = 1/2 degree
52
+ mult2_ = 2, // 6th char gives 2x more precision
53
+ mult3_ = 3, // 7th char gives 3x more precision
54
+ m_ = mult1_ * mult2_ * mult3_,
55
+ maxprec_ = 2,
56
+ maxlen_ = baselen_ + maxprec_,
57
+ };
58
+ GARS(); // Disable constructor
59
+
60
+ public:
61
+
62
+ /**
63
+ * Convert from geographic coordinates to GARS.
64
+ *
65
+ * @param[in] lat latitude of point (degrees).
66
+ * @param[in] lon longitude of point (degrees).
67
+ * @param[in] prec the precision of the resulting GARS.
68
+ * @param[out] gars the GARS string.
69
+ * @exception GeographicErr if \e lat is not in [&minus;90&deg;,
70
+ * 90&deg;].
71
+ * @exception std::bad_alloc if memory for \e gars can't be allocated.
72
+ *
73
+ * \e prec specifies the precision of \e gars as follows:
74
+ * - \e prec = 0 (min), 30' precision, e.g., 006AG;
75
+ * - \e prec = 1, 15' precision, e.g., 006AG3;
76
+ * - \e prec = 2 (max), 5' precision, e.g., 006AG39.
77
+ *
78
+ * If \e lat or \e lon is NaN, then \e gars is set to "INVALID".
79
+ **********************************************************************/
80
+ static void Forward(real lat, real lon, int prec, std::string& gars);
81
+
82
+ /**
83
+ * Convert from GARS to geographic coordinates.
84
+ *
85
+ * @param[in] gars the GARS.
86
+ * @param[out] lat latitude of point (degrees).
87
+ * @param[out] lon longitude of point (degrees).
88
+ * @param[out] prec the precision of \e gars.
89
+ * @param[in] centerp if true (the default) return the center of the
90
+ * \e gars, otherwise return the south-west corner.
91
+ * @exception GeographicErr if \e gars is illegal.
92
+ *
93
+ * The case of the letters in \e gars is ignored. \e prec is in the range
94
+ * [0, 2] and gives the precision of \e gars as follows:
95
+ * - \e prec = 0 (min), 30' precision, e.g., 006AG;
96
+ * - \e prec = 1, 15' precision, e.g., 006AG3;
97
+ * - \e prec = 2 (max), 5' precision, e.g., 006AG39.
98
+ *
99
+ * If the first 3 characters of \e gars are "INV", then \e lat and \e lon
100
+ * are set to NaN and \e prec is unchanged.
101
+ **********************************************************************/
102
+ static void Reverse(const std::string& gars, real& lat, real& lon,
103
+ int& prec, bool centerp = true);
104
+
105
+ /**
106
+ * The angular resolution of a GARS.
107
+ *
108
+ * @param[in] prec the precision of the GARS.
109
+ * @return the latitude-longitude resolution (degrees).
110
+ *
111
+ * Internally, \e prec is first put in the range [0, 2].
112
+ **********************************************************************/
113
+ static Math::real Resolution(int prec) {
114
+ return 1/real(prec <= 0 ? mult1_ : (prec == 1 ? mult1_ * mult2_ :
115
+ mult1_ * mult2_ * mult3_));
116
+ }
117
+
118
+ /**
119
+ * The GARS precision required to meet a given geographic resolution.
120
+ *
121
+ * @param[in] res the minimum of resolution in latitude and longitude
122
+ * (degrees).
123
+ * @return GARS precision.
124
+ *
125
+ * The returned length is in the range [0, 2].
126
+ **********************************************************************/
127
+ static int Precision(real res) {
128
+ using std::abs; res = abs(res);
129
+ for (int prec = 0; prec < maxprec_; ++prec)
130
+ if (Resolution(prec) <= res)
131
+ return prec;
132
+ return maxprec_;
133
+ }
134
+
135
+ };
136
+
137
+ } // namespace GeographicLib
138
+
139
+ #if defined(_MSC_VER)
140
+ # pragma warning (pop)
141
+ #endif
142
+
143
+ #endif // GEOGRAPHICLIB_GARS_HPP
@@ -0,0 +1,544 @@
1
+ /**
2
+ * \file GeoCoords.hpp
3
+ * \brief Header for GeographicLib::GeoCoords class
4
+ *
5
+ * Copyright (c) Charles Karney (2008-2015) <charles@karney.com> and licensed
6
+ * under the MIT/X11 License. For more information, see
7
+ * http://geographiclib.sourceforge.net/
8
+ **********************************************************************/
9
+
10
+ #if !defined(GEOGRAPHICLIB_GEOCOORDS_HPP)
11
+ #define GEOGRAPHICLIB_GEOCOORDS_HPP 1
12
+
13
+ #include <GeographicLib/UTMUPS.hpp>
14
+ #include <GeographicLib/Constants.hpp>
15
+
16
+ namespace GeographicLib {
17
+
18
+ /**
19
+ * \brief Conversion between geographic coordinates
20
+ *
21
+ * This class stores a geographic position which may be set via the
22
+ * constructors or Reset via
23
+ * - latitude and longitude
24
+ * - UTM or UPS coordinates
25
+ * - a string representation of these or an MGRS coordinate string
26
+ *
27
+ * The state consists of the latitude and longitude and the supplied UTM or
28
+ * UPS coordinates (possibly derived from the MGRS coordinates). If latitude
29
+ * and longitude were given then the UTM/UPS coordinates follows the standard
30
+ * conventions.
31
+ *
32
+ * The mutable state consists of the UTM or UPS coordinates for a alternate
33
+ * zone. A method SetAltZone is provided to set the alternate UPS/UTM zone.
34
+ *
35
+ * Methods are provided to return the geographic coordinates, the input UTM
36
+ * or UPS coordinates (and associated meridian convergence and scale), or
37
+ * alternate UTM or UPS coordinates (and their associated meridian
38
+ * convergence and scale).
39
+ *
40
+ * Once the input string has been parsed, you can print the result out in any
41
+ * of the formats, decimal degrees, degrees minutes seconds, MGRS, UTM/UPS.
42
+ *
43
+ * Example of use:
44
+ * \include example-GeoCoords.cpp
45
+ *
46
+ * <a href="GeoConvert.1.html">GeoConvert</a> is a command-line utility
47
+ * providing access to the functionality of GeoCoords.
48
+ **********************************************************************/
49
+ class GEOGRAPHICLIB_EXPORT GeoCoords {
50
+ private:
51
+ typedef Math::real real;
52
+ real _lat, _long, _easting, _northing, _gamma, _k;
53
+ bool _northp;
54
+ int _zone; // See UTMUPS::zonespec
55
+ mutable real _alt_easting, _alt_northing, _alt_gamma, _alt_k;
56
+ mutable int _alt_zone;
57
+
58
+ void CopyToAlt() const {
59
+ _alt_easting = _easting;
60
+ _alt_northing = _northing;
61
+ _alt_gamma = _gamma;
62
+ _alt_k = _k;
63
+ _alt_zone = _zone;
64
+ }
65
+ static void UTMUPSString(int zone, bool northp, real easting, real northing,
66
+ int prec, bool abbrev, std::string& utm);
67
+ void FixHemisphere();
68
+ public:
69
+
70
+ /** \name Initializing the GeoCoords object
71
+ **********************************************************************/
72
+ ///@{
73
+ /**
74
+ * The default constructor sets the coordinate as undefined.
75
+ **********************************************************************/
76
+ GeoCoords()
77
+ : _lat(Math::NaN())
78
+ , _long(Math::NaN())
79
+ , _easting(Math::NaN())
80
+ , _northing(Math::NaN())
81
+ , _gamma(Math::NaN())
82
+ , _k(Math::NaN())
83
+ , _northp(false)
84
+ , _zone(UTMUPS::INVALID)
85
+ { CopyToAlt(); }
86
+
87
+ /**
88
+ * Construct from a string.
89
+ *
90
+ * @param[in] s 1-element, 2-element, or 3-element string representation of
91
+ * the position.
92
+ * @param[in] centerp governs the interpretation of MGRS coordinates (see
93
+ * below).
94
+ * @param[in] longfirst governs the interpretation of geographic
95
+ * coordinates (see below).
96
+ * @exception GeographicErr if the \e s is malformed (see below).
97
+ *
98
+ * Parse as a string and interpret it as a geographic position. The input
99
+ * string is broken into space (or comma) separated pieces and Basic
100
+ * decision on which format is based on number of components
101
+ * -# MGRS
102
+ * -# "Lat Long" or "Long Lat"
103
+ * -# "Zone Easting Northing" or "Easting Northing Zone"
104
+ *
105
+ * The following inputs are approximately the same (Ar Ramadi Bridge, Iraq)
106
+ * - Latitude and Longitude
107
+ * - 33.44 43.27
108
+ * - N33d26.4' E43d16.2'
109
+ * - 43d16'12&quot;E 33d26'24&quot;N
110
+ * - 43:16:12E 33:26:24
111
+ * - MGRS
112
+ * - 38SLC30
113
+ * - 38SLC391014
114
+ * - 38SLC3918701405
115
+ * - 37SHT9708
116
+ * - UTM
117
+ * - 38n 339188 3701405
118
+ * - 897039 3708229 37n
119
+ *
120
+ * <b>Latitude and Longitude parsing</b>: Latitude precedes longitude,
121
+ * unless a N, S, E, W hemisphere designator is used on one or both
122
+ * coordinates. If \e longfirst = true (default is false), then
123
+ * longitude precedes latitude in the absence of a hemisphere designator.
124
+ * Thus (with \e longfirst = false)
125
+ * - 40 -75
126
+ * - N40 W75
127
+ * - -75 N40
128
+ * - 75W 40N
129
+ * - E-75 -40S
130
+ * .
131
+ * are all the same position. The coordinates may be given in
132
+ * decimal degrees, degrees and decimal minutes, degrees, minutes,
133
+ * seconds, etc. Use d, ', and &quot; to mark off the degrees,
134
+ * minutes and seconds. Various alternative symbols for degrees, minutes,
135
+ * and seconds are allowed. Alternatively, use : to separate these
136
+ * components. A single addition or subtraction is allowed. (See
137
+ * DMS::Decode for details.) Thus
138
+ * - 40d30'30&quot;
139
+ * - 40d30'30
140
+ * - 40&deg;30'30
141
+ * - 40d30.5'
142
+ * - 40d30.5
143
+ * - 40:30:30
144
+ * - 40:30.5
145
+ * - 40.508333333
146
+ * - 40:30+0:0:30
147
+ * - 40:31-0:0.5
148
+ * .
149
+ * all specify the same angle. The leading sign applies to the following
150
+ * components so -1d30 is -(1+30/60) = &minus;1.5. However, note
151
+ * that -1:30-0:0:15 is parsed as (-1:30) + (-0:0:15) = &minus;(1+30/60)
152
+ * &minus; (15/3600). Latitudes must be in the range [&minus;90&deg;,
153
+ * 90&deg;]. Internally longitudes are reduced to the range
154
+ * [&minus;180&deg;, 180&deg;).
155
+ *
156
+ * <b>UTM/UPS parsing</b>: For UTM zones (&minus;80&deg; &le; Lat <
157
+ * 84&deg;), the zone designator is made up of a zone number (for 1 to 60)
158
+ * and a hemisphere letter (n or s), e.g., 38n (38north can also be used).
159
+ * The latitude band designer ([C--M] in the southern hemisphere and [N--X]
160
+ * in the northern) should NOT be used. (This is part of the MGRS
161
+ * coordinate.) The zone designator for the poles (where UPS is employed)
162
+ * is a hemisphere letter by itself, i.e., n or s (north or south can also
163
+ * be used).
164
+ *
165
+ * <b>MGRS parsing</b> interprets the grid references as square area at the
166
+ * specified precision (1m, 10m, 100m, etc.). If \e centerp = true (the
167
+ * default), the center of this square is then taken to be the precise
168
+ * position; thus:
169
+ * - 38SMB = 38n 450000 3650000
170
+ * - 38SMB4484 = 38n 444500 3684500
171
+ * - 38SMB44148470 = 38n 444145 3684705
172
+ * .
173
+ * Otherwise, the "south-west" corner of the square is used, i.e.,
174
+ * - 38SMB = 38n 400000 3600000
175
+ * - 38SMB4484 = 38n 444000 3684000
176
+ * - 38SMB44148470 = 38n 444140 3684700
177
+ **********************************************************************/
178
+ explicit GeoCoords(const std::string& s,
179
+ bool centerp = true, bool longfirst = false)
180
+ { Reset(s, centerp, longfirst); }
181
+
182
+ /**
183
+ * Construct from geographic coordinates.
184
+ *
185
+ * @param[in] latitude (degrees).
186
+ * @param[in] longitude (degrees).
187
+ * @param[in] zone if specified, force the UTM/UPS representation to use a
188
+ * specified zone using the rules given in UTMUPS::zonespec.
189
+ * @exception GeographicErr if \e latitude is not in [&minus;90&deg;,
190
+ * 90&deg;].
191
+ * @exception GeographicErr if \e zone cannot be used for this location.
192
+ **********************************************************************/
193
+ GeoCoords(real latitude, real longitude, int zone = UTMUPS::STANDARD) {
194
+ Reset(latitude, longitude, zone);
195
+ }
196
+
197
+ /**
198
+ * Construct from UTM/UPS coordinates.
199
+ *
200
+ * @param[in] zone UTM zone (zero means UPS).
201
+ * @param[in] northp hemisphere (true means north, false means south).
202
+ * @param[in] easting (meters).
203
+ * @param[in] northing (meters).
204
+ * @exception GeographicErr if \e zone, \e easting, or \e northing is
205
+ * outside its allowed range.
206
+ **********************************************************************/
207
+ GeoCoords(int zone, bool northp, real easting, real northing) {
208
+ Reset(zone, northp, easting, northing);
209
+ }
210
+
211
+ /**
212
+ * Reset the location from a string. See
213
+ * GeoCoords(const std::string& s, bool centerp, bool longfirst).
214
+ *
215
+ * @param[in] s 1-element, 2-element, or 3-element string representation of
216
+ * the position.
217
+ * @param[in] centerp governs the interpretation of MGRS coordinates.
218
+ * @param[in] longfirst governs the interpretation of geographic
219
+ * coordinates.
220
+ * @exception GeographicErr if the \e s is malformed.
221
+ **********************************************************************/
222
+ void Reset(const std::string& s,
223
+ bool centerp = true, bool longfirst = false);
224
+
225
+ /**
226
+ * Reset the location in terms of geographic coordinates. See
227
+ * GeoCoords(real latitude, real longitude, int zone).
228
+ *
229
+ * @param[in] latitude (degrees).
230
+ * @param[in] longitude (degrees).
231
+ * @param[in] zone if specified, force the UTM/UPS representation to use a
232
+ * specified zone using the rules given in UTMUPS::zonespec.
233
+ * @exception GeographicErr if \e latitude is not in [&minus;90&deg;,
234
+ * 90&deg;].
235
+ * @exception GeographicErr if \e zone cannot be used for this location.
236
+ **********************************************************************/
237
+ void Reset(real latitude, real longitude, int zone = UTMUPS::STANDARD) {
238
+ UTMUPS::Forward(latitude, longitude,
239
+ _zone, _northp, _easting, _northing, _gamma, _k,
240
+ zone);
241
+ _lat = latitude;
242
+ _long = longitude;
243
+ if (_long >= 180) _long -= 360;
244
+ else if (_long < -180) _long += 360;
245
+ CopyToAlt();
246
+ }
247
+
248
+ /**
249
+ * Reset the location in terms of UPS/UPS coordinates. See
250
+ * GeoCoords(int zone, bool northp, real easting, real northing).
251
+ *
252
+ * @param[in] zone UTM zone (zero means UPS).
253
+ * @param[in] northp hemisphere (true means north, false means south).
254
+ * @param[in] easting (meters).
255
+ * @param[in] northing (meters).
256
+ * @exception GeographicErr if \e zone, \e easting, or \e northing is
257
+ * outside its allowed range.
258
+ **********************************************************************/
259
+ void Reset(int zone, bool northp, real easting, real northing) {
260
+ UTMUPS::Reverse(zone, northp, easting, northing,
261
+ _lat, _long, _gamma, _k);
262
+ _zone = zone;
263
+ _northp = northp;
264
+ _easting = easting;
265
+ _northing = northing;
266
+ FixHemisphere();
267
+ CopyToAlt();
268
+ }
269
+ ///@}
270
+
271
+ /** \name Querying the GeoCoords object
272
+ **********************************************************************/
273
+ ///@{
274
+ /**
275
+ * @return latitude (degrees)
276
+ **********************************************************************/
277
+ Math::real Latitude() const { return _lat; }
278
+
279
+ /**
280
+ * @return longitude (degrees)
281
+ **********************************************************************/
282
+ Math::real Longitude() const { return _long; }
283
+
284
+ /**
285
+ * @return easting (meters)
286
+ **********************************************************************/
287
+ Math::real Easting() const { return _easting; }
288
+
289
+ /**
290
+ * @return northing (meters)
291
+ **********************************************************************/
292
+ Math::real Northing() const { return _northing; }
293
+
294
+ /**
295
+ * @return meridian convergence (degrees) for the UTM/UPS projection.
296
+ **********************************************************************/
297
+ Math::real Convergence() const { return _gamma; }
298
+
299
+ /**
300
+ * @return scale for the UTM/UPS projection.
301
+ **********************************************************************/
302
+ Math::real Scale() const { return _k; }
303
+
304
+ /**
305
+ * @return hemisphere (false means south, true means north).
306
+ **********************************************************************/
307
+ bool Northp() const { return _northp; }
308
+
309
+ /**
310
+ * @return hemisphere letter n or s.
311
+ **********************************************************************/
312
+ char Hemisphere() const { return _northp ? 'n' : 's'; }
313
+
314
+ /**
315
+ * @return the zone corresponding to the input (return 0 for UPS).
316
+ **********************************************************************/
317
+ int Zone() const { return _zone; }
318
+
319
+ ///@}
320
+
321
+ /** \name Setting and querying the alternate zone
322
+ **********************************************************************/
323
+ ///@{
324
+ /**
325
+ * Specify alternate zone number.
326
+ *
327
+ * @param[in] zone zone number for the alternate representation.
328
+ * @exception GeographicErr if \e zone cannot be used for this location.
329
+ *
330
+ * See UTMUPS::zonespec for more information on the interpretation of \e
331
+ * zone. Note that \e zone == UTMUPS::STANDARD (the default) use the
332
+ * standard UPS or UTM zone, UTMUPS::MATCH does nothing retaining the
333
+ * existing alternate representation. Before this is called the alternate
334
+ * zone is the input zone.
335
+ **********************************************************************/
336
+ void SetAltZone(int zone = UTMUPS::STANDARD) const {
337
+ if (zone == UTMUPS::MATCH)
338
+ return;
339
+ zone = UTMUPS::StandardZone(_lat, _long, zone);
340
+ if (zone == _zone)
341
+ CopyToAlt();
342
+ else {
343
+ bool northp;
344
+ UTMUPS::Forward(_lat, _long,
345
+ _alt_zone, northp,
346
+ _alt_easting, _alt_northing, _alt_gamma, _alt_k,
347
+ zone);
348
+ }
349
+ }
350
+
351
+ /**
352
+ * @return current alternate zone (return 0 for UPS).
353
+ **********************************************************************/
354
+ int AltZone() const { return _alt_zone; }
355
+
356
+ /**
357
+ * @return easting (meters) for alternate zone.
358
+ **********************************************************************/
359
+ Math::real AltEasting() const { return _alt_easting; }
360
+
361
+ /**
362
+ * @return northing (meters) for alternate zone.
363
+ **********************************************************************/
364
+ Math::real AltNorthing() const { return _alt_northing; }
365
+
366
+ /**
367
+ * @return meridian convergence (degrees) for alternate zone.
368
+ **********************************************************************/
369
+ Math::real AltConvergence() const { return _alt_gamma; }
370
+
371
+ /**
372
+ * @return scale for alternate zone.
373
+ **********************************************************************/
374
+ Math::real AltScale() const { return _alt_k; }
375
+ ///@}
376
+
377
+ /** \name String representations of the GeoCoords object
378
+ **********************************************************************/
379
+ ///@{
380
+ /**
381
+ * String representation with latitude and longitude as signed decimal
382
+ * degrees.
383
+ *
384
+ * @param[in] prec precision (relative to about 1m).
385
+ * @param[in] longfirst if true give longitude first (default = false)
386
+ * @exception std::bad_alloc if memory for the string can't be allocated.
387
+ * @return decimal latitude/longitude string representation.
388
+ *
389
+ * Precision specifies accuracy of representation as follows:
390
+ * - prec = &minus;5 (min), 1&deg;
391
+ * - prec = 0, 10<sup>&minus;5</sup>&deg; (about 1m)
392
+ * - prec = 3, 10<sup>&minus;8</sup>&deg;
393
+ * - prec = 9 (max), 10<sup>&minus;14</sup>&deg;
394
+ **********************************************************************/
395
+ std::string GeoRepresentation(int prec = 0, bool longfirst = false) const;
396
+
397
+ /**
398
+ * String representation with latitude and longitude as degrees, minutes,
399
+ * seconds, and hemisphere.
400
+ *
401
+ * @param[in] prec precision (relative to about 1m)
402
+ * @param[in] longfirst if true give longitude first (default = false)
403
+ * @param[in] dmssep if non-null, use as the DMS separator character
404
+ * (instead of d, ', &quot; delimiters).
405
+ * @exception std::bad_alloc if memory for the string can't be allocated.
406
+ * @return DMS latitude/longitude string representation.
407
+ *
408
+ * Precision specifies accuracy of representation as follows:
409
+ * - prec = &minus;5 (min), 1&deg;
410
+ * - prec = &minus;4, 0.1&deg;
411
+ * - prec = &minus;3, 1'
412
+ * - prec = &minus;2, 0.1'
413
+ * - prec = &minus;1, 1&quot;
414
+ * - prec = 0, 0.1&quot; (about 3m)
415
+ * - prec = 1, 0.01&quot;
416
+ * - prec = 10 (max), 10<sup>&minus;11</sup>&quot;
417
+ **********************************************************************/
418
+ std::string DMSRepresentation(int prec = 0, bool longfirst = false,
419
+ char dmssep = char(0))
420
+ const;
421
+
422
+ /**
423
+ * MGRS string.
424
+ *
425
+ * @param[in] prec precision (relative to about 1m).
426
+ * @exception std::bad_alloc if memory for the string can't be allocated.
427
+ * @return MGRS string.
428
+ *
429
+ * This gives the coordinates of the enclosing grid square with size given
430
+ * by the precision. Thus 38n 444180 3684790 converted to a MGRS
431
+ * coordinate at precision &minus;2 (100m) is 38SMB441847 and not
432
+ * 38SMB442848. \e prec specifies the precision of the MGRS string as
433
+ * follows:
434
+ * - prec = &minus;5 (min), 100km
435
+ * - prec = &minus;4, 10km
436
+ * - prec = &minus;3, 1km
437
+ * - prec = &minus;2, 100m
438
+ * - prec = &minus;1, 10m
439
+ * - prec = 0, 1m
440
+ * - prec = 1, 0.1m
441
+ * - prec = 6 (max), 1&mu;m
442
+ **********************************************************************/
443
+ std::string MGRSRepresentation(int prec = 0) const;
444
+
445
+ /**
446
+ * UTM/UPS string.
447
+ *
448
+ * @param[in] prec precision (relative to about 1m)
449
+ * @param[in] abbrev if true (the default) use abbreviated (n/s) notation
450
+ * for hemisphere; otherwise spell out the hemisphere (north/south)
451
+ * @exception std::bad_alloc if memory for the string can't be allocated.
452
+ * @return UTM/UPS string representation: zone designator, easting, and
453
+ * northing.
454
+ *
455
+ * Precision specifies accuracy of representation as follows:
456
+ * - prec = &minus;5 (min), 100km
457
+ * - prec = &minus;3, 1km
458
+ * - prec = 0, 1m
459
+ * - prec = 3, 1mm
460
+ * - prec = 6, 1&mu;m
461
+ * - prec = 9 (max), 1nm
462
+ **********************************************************************/
463
+ std::string UTMUPSRepresentation(int prec = 0, bool abbrev = true) const;
464
+
465
+ /**
466
+ * UTM/UPS string with hemisphere override.
467
+ *
468
+ * @param[in] northp hemisphere override
469
+ * @param[in] prec precision (relative to about 1m)
470
+ * @param[in] abbrev if true (the default) use abbreviated (n/s) notation
471
+ * for hemisphere; otherwise spell out the hemisphere (north/south)
472
+ * @exception GeographicErr if the hemisphere override attempts to change
473
+ * UPS N to UPS S or vice versa.
474
+ * @exception std::bad_alloc if memory for the string can't be allocated.
475
+ * @return UTM/UPS string representation: zone designator, easting, and
476
+ * northing.
477
+ **********************************************************************/
478
+ std::string UTMUPSRepresentation(bool northp, int prec = 0,
479
+ bool abbrev = true) const;
480
+
481
+ /**
482
+ * MGRS string for the alternate zone. See GeoCoords::MGRSRepresentation.
483
+ *
484
+ * @param[in] prec precision (relative to about 1m).
485
+ * @exception std::bad_alloc if memory for the string can't be allocated.
486
+ * @return MGRS string.
487
+ **********************************************************************/
488
+ std::string AltMGRSRepresentation(int prec = 0) const;
489
+
490
+ /**
491
+ * UTM/UPS string for the alternate zone. See
492
+ * GeoCoords::UTMUPSRepresentation.
493
+ *
494
+ * @param[in] prec precision (relative to about 1m)
495
+ * @param[in] abbrev if true (the default) use abbreviated (n/s) notation
496
+ * for hemisphere; otherwise spell out the hemisphere (north/south)
497
+ * @exception std::bad_alloc if memory for the string can't be allocated.
498
+ * @return UTM/UPS string representation: zone designator, easting, and
499
+ * northing.
500
+ **********************************************************************/
501
+ std::string AltUTMUPSRepresentation(int prec = 0, bool abbrev = true) const;
502
+
503
+ /**
504
+ * UTM/UPS string for the alternate zone, with hemisphere override.
505
+ *
506
+ * @param[in] northp hemisphere override
507
+ * @param[in] prec precision (relative to about 1m)
508
+ * @param[in] abbrev if true (the default) use abbreviated (n/s) notation
509
+ * for hemisphere; otherwise spell out the hemisphere (north/south)
510
+ * @exception GeographicErr if the hemisphere override attempts to change
511
+ * UPS n to UPS s or vice verse.
512
+ * @exception std::bad_alloc if memory for the string can't be allocated.
513
+ * @return UTM/UPS string representation: zone designator, easting, and
514
+ * northing.
515
+ **********************************************************************/
516
+ std::string AltUTMUPSRepresentation(bool northp, int prec = 0,
517
+ bool abbrev = true) const;
518
+ ///@}
519
+
520
+ /** \name Inspector functions
521
+ **********************************************************************/
522
+ ///@{
523
+ /**
524
+ * @return \e a the equatorial radius of the WGS84 ellipsoid (meters).
525
+ *
526
+ * (The WGS84 value is returned because the UTM and UPS projections are
527
+ * based on this ellipsoid.)
528
+ **********************************************************************/
529
+ Math::real MajorRadius() const { return UTMUPS::MajorRadius(); }
530
+
531
+ /**
532
+ * @return \e f the flattening of the WGS84 ellipsoid.
533
+ *
534
+ * (The WGS84 value is returned because the UTM and UPS projections are
535
+ * based on this ellipsoid.)
536
+ **********************************************************************/
537
+ Math::real Flattening() const { return UTMUPS::Flattening(); }
538
+ ///@}
539
+
540
+ };
541
+
542
+ } // namespace GeographicLib
543
+
544
+ #endif // GEOGRAPHICLIB_GEOCOORDS_HPP