NETGeographicLib  1.43
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Pages
GeoCoords.h
Go to the documentation of this file.
1 /**
2  * \file NETGeographicLib/GeoCoords.h
3  * \brief Header for NETGeographicLib::GeoCoords 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  * http://geographiclib.sourceforge.net/
10  **********************************************************************/
11 #pragma once
12 
13 namespace NETGeographicLib
14 {
15  /**
16  * \brief .NET wrapper for GeographicLib::GeoCoords.
17  *
18  * This class allows .NET applications to access GeographicLib::GeoCoords.
19  *
20  * This class stores a geographic position which may be set via the
21  * constructors or Reset via
22  * - latitude and longitude
23  * - UTM or UPS coordinates
24  * - a string representation of these or an MGRS coordinate string
25  *
26  * The state consists of the latitude and longitude and the supplied UTM or
27  * UPS coordinates (possibly derived from the MGRS coordinates). If latitude
28  * and longitude were given then the UTM/UPS coordinates follows the standard
29  * conventions.
30  *
31  * The mutable state consists of the UTM or UPS coordinates for a alternate
32  * zone. A method SetAltZone is provided to set the alternate UPS/UTM zone.
33  *
34  * Methods are provided to return the geographic coordinates, the input UTM
35  * or UPS coordinates (and associated meridian convergence and scale), or
36  * alternate UTM or UPS coordinates (and their associated meridian
37  * convergence and scale).
38  *
39  * Once the input string has been parsed, you can print the result out in any
40  * of the formats, decimal degrees, degrees minutes seconds, MGRS, UTM/UPS.
41  *
42  * C# Example:
43  * \include example-GeoCoords.cs
44  * Managed C++ Example:
45  * \include example-GeoCoords.cpp
46  * Visual Basic Example:
47  * \include example-GeoCoords.vb
48  *
49  * <B>INTERFACE DIFFERENCES:</B><BR>
50  * The following functions are implemented as properties: MajorRadius,
51  * Flattening, Latitude, Longitude, Easting, Northing, Convergence,
52  * Scale, Northp, Hemisphere, Zone, AltZone, AltEasting, AltNorthing,
53  * AltConvergence, and AltScale.
54  **********************************************************************/
55  public ref class GeoCoords
56  {
57  private:
58  // pointer to the unmanaged GeographicLib::GeoCoords
59  GeographicLib::GeoCoords* m_pGeoCoords;
60 
61  // The finalizer frees unmanaged memory when the object is destroyed.
62  !GeoCoords();
63  public:
64  /** \name Initializing the GeoCoords object
65  **********************************************************************/
66  ///@{
67  /**
68  * The default constructor sets the coordinate as undefined.
69  **********************************************************************/
70  GeoCoords();
71 
72  /**
73  * Construct from a string.
74  *
75  * @param[in] s 1-element, 2-element, or 3-element string representation of
76  * the position.
77  * @param[in] centerp governs the interpretation of MGRS coordinates (see
78  * below).
79  * @param[in] swaplatlong governs the interpretation of geographic
80  * coordinates (see below).
81  * @exception GeographicErr if the \e s is malformed (see below).
82  *
83  * Parse as a string and interpret it as a geographic position. The input
84  * string is broken into space (or comma) separated pieces and Basic
85  * decision on which format is based on number of components
86  * -# MGRS
87  * -# "Lat Long" or "Long Lat"
88  * -# "Zone Easting Northing" or "Easting Northing Zone"
89  *
90  * The following inputs are approximately the same (Ar Ramadi Bridge, Iraq)
91  * - Latitude and Longitude
92  * - 33.44 43.27
93  * - N33d26.4' E43d16.2'
94  * - 43d16'12&quot;E 33d26'24&quot;N
95  * - 43:16:12E 33:26:24
96  * - MGRS
97  * - 38SLC30
98  * - 38SLC391014
99  * - 38SLC3918701405
100  * - 37SHT9708
101  * - UTM
102  * - 38N 339188 3701405
103  * - 897039 3708229 37N
104  *
105  * <b>Latitude and Longitude parsing</b>: Latitude precedes longitude,
106  * unless a N, S, E, W hemisphere designator is used on one or both
107  * coordinates. If \e swaplatlong = true (default is false), then
108  * longitude precedes latitude in the absence of a hemisphere designator.
109  * Thus (with \e swaplatlong = false)
110  * - 40 -75
111  * - N40 W75
112  * - -75 N40
113  * - 75W 40N
114  * - E-75 -40S
115  * .
116  * are all the same position. The coordinates may be given in
117  * decimal degrees, degrees and decimal minutes, degrees, minutes,
118  * seconds, etc. Use d, ', and &quot; to mark off the degrees,
119  * minutes and seconds. Various alternative symbols for degrees, minutes,
120  * and seconds are allowed. Alternatively, use : to separate these
121  * components. (See DMS::Decode for details.) Thus
122  * - 40d30'30&quot;
123  * - 40d30'30
124  * - 40&deg;30'30
125  * - 40d30.5'
126  * - 40d30.5
127  * - 40:30:30
128  * - 40:30.5
129  * - 40.508333333
130  * .
131  * all specify the same angle. The leading sign applies to all components
132  * so -1d30 is -(1+30/60) = -1.5. Latitudes must be in the range
133  * [&minus;90&deg;, 90&deg;] and longitudes in the range
134  * [&minus;540&deg;, 540&deg;). Internally longitudes are reduced
135  * to the range [&minus;180&deg;, 180&deg;).
136  *
137  * <b>UTM/UPS parsing</b>: For UTM zones (&minus;80&deg; &le; Lat <
138  * 84&deg;), the zone designator is made up of a zone number (for 1 to 60)
139  * and a hemisphere letter (N or S), e.g., 38N. The latitude zone designer
140  * ([C--M] in the southern hemisphere and [N--X] in the northern) should
141  * NOT be used. (This is part of the MGRS coordinate.) The zone
142  * designator for the poles (where UPS is employed) is a hemisphere letter
143  * by itself, i.e., N or S.
144  *
145  * <b>MGRS parsing</b> interprets the grid references as square area at the
146  * specified precision (1m, 10m, 100m, etc.). If \e centerp = true (the
147  * default), the center of this square is then taken to be the precise
148  * position; thus:
149  * - 38SMB = 38N 450000 3650000
150  * - 38SMB4484 = 38N 444500 3684500
151  * - 38SMB44148470 = 38N 444145 3684705
152  * .
153  * Otherwise, the "south-west" corner of the square is used, i.e.,
154  * - 38SMB = 38N 400000 3600000
155  * - 38SMB4484 = 38N 444000 3684000
156  * - 38SMB44148470 = 38N 444140 3684700
157  **********************************************************************/
158  GeoCoords(System::String^ s, bool centerp, bool swaplatlong );
159 
160  /**
161  * Construct from geographic coordinates.
162  *
163  * @param[in] latitude (degrees).
164  * @param[in] longitude (degrees).
165  * @param[in] zone if specified, force the UTM/UPS representation to use a
166  * specified zone using the rules given in UTMUPS::zonespec.
167  * @exception GeographicErr if \e latitude is not in [&minus;90&deg;,
168  * 90&deg;].
169  * @exception GeographicErr if \e longitude is not in [&minus;540&deg;,
170  * 540&deg;).
171  * @exception GeographicErr if \e zone cannot be used for this location.
172  **********************************************************************/
173  GeoCoords(double latitude, double longitude, int zone );
174 
175  /**
176  * Construct from UTM/UPS coordinates.
177  *
178  * @param[in] zone UTM zone (zero means UPS).
179  * @param[in] northp hemisphere (true means north, false means south).
180  * @param[in] easting (meters).
181  * @param[in] northing (meters).
182  * @exception GeographicErr if \e zone, \e easting, or \e northing is
183  * outside its allowed range.
184  **********************************************************************/
185  GeoCoords(int zone, bool northp, double easting, double northing);
186 
187  /**
188  * The destructor calls the finalizer.
189  **********************************************************************/
190  ~GeoCoords() { this->!GeoCoords(); }
191 
192  /**
193  * Reset the location from a string. See
194  * GeoCoords(const std::string& s, bool centerp, bool swaplatlong).
195  *
196  * @param[in] s 1-element, 2-element, or 3-element string representation of
197  * the position.
198  * @param[in] centerp governs the interpretation of MGRS coordinates.
199  * @param[in] swaplatlong governs the interpretation of geographic
200  * coordinates.
201  * @exception GeographicErr if the \e s is malformed.
202  **********************************************************************/
203  void Reset( System::String^ s, bool centerp, bool swaplatlong);
204 
205  /**
206  * Reset the location in terms of geographic coordinates. See
207  * GeoCoords(double latitude, double longitude, int zone).
208  *
209  * @param[in] latitude (degrees).
210  * @param[in] longitude (degrees).
211  * @param[in] zone if specified, force the UTM/UPS representation to use a
212  * specified zone using the rules given in UTMUPS::zonespec.
213  * @exception GeographicErr if \e latitude is not in [&minus;90&deg;,
214  * 90&deg;].
215  * @exception GeographicErr if \e longitude is not in [&minus;540&deg;,
216  * 540&deg;).
217  * @exception GeographicErr if \e zone cannot be used for this location.
218  **********************************************************************/
219  void Reset(double latitude, double longitude, int zone ) ;
220 
221  /**
222  * Reset the location in terms of UPS/UPS coordinates. See
223  * GeoCoords(int zone, bool northp, double easting, double northing).
224  *
225  * @param[in] zone UTM zone (zero means UPS).
226  * @param[in] northp hemisphere (true means north, false means south).
227  * @param[in] easting (meters).
228  * @param[in] northing (meters).
229  * @exception GeographicErr if \e zone, \e easting, or \e northing is
230  * outside its allowed range.
231  **********************************************************************/
232  void Reset(int zone, bool northp, double easting, double northing);
233  ///@}
234 
235  /** \name Querying the GeoCoords object
236  **********************************************************************/
237  ///@{
238  /**
239  * @return latitude (degrees)
240  **********************************************************************/
241  property double Latitude { double get(); }
242 
243  /**
244  * @return longitude (degrees)
245  **********************************************************************/
246  property double Longitude { double get(); }
247 
248  /**
249  * @return easting (meters)
250  **********************************************************************/
251  property double Easting { double get(); }
252 
253  /**
254  * @return northing (meters)
255  **********************************************************************/
256  property double Northing { double get(); }
257 
258  /**
259  * @return meridian convergence (degrees) for the UTM/UPS projection.
260  **********************************************************************/
261  property double Convergence { double get(); }
262 
263  /**
264  * @return scale for the UTM/UPS projection.
265  **********************************************************************/
266  property double Scale { double get(); }
267 
268  /**
269  * @return hemisphere (false means south, true means north).
270  **********************************************************************/
271  property bool Northp { bool get(); }
272 
273  /**
274  * @return hemisphere letter N or S.
275  **********************************************************************/
276  property char Hemisphere { char get(); }
277 
278  /**
279  * @return the zone corresponding to the input (return 0 for UPS).
280  **********************************************************************/
281  property int Zone { int get(); }
282 
283  /**
284  * Gets/Sets the current alternate zone (0 = UPS).
285  * @exception GeographicErr if \e zone cannot be used for this location.
286  *
287  * See UTMUPS::zonespec for more information on the interpretation of \e
288  * zone. Note that \e zone == UTMUPS::STANDARD (the default) use the
289  * standard UPS or UTM zone, UTMUPS::MATCH does nothing retaining the
290  * existing alternate representation. Before this is called the alternate
291  * zone is the input zone.
292  **********************************************************************/
293  property int AltZone
294  {
295  int get();
296  void set( int zone );
297  }
298  ///@}
299 
300  /**
301  * @return easting (meters) for alternate zone.
302  **********************************************************************/
303  property double AltEasting { double get(); }
304 
305  /**
306  * @return northing (meters) for alternate zone.
307  **********************************************************************/
308  property double AltNorthing { double get(); }
309 
310  /**
311  * @return meridian convergence (degrees) for alternate zone.
312  **********************************************************************/
313  property double AltConvergence { double get(); }
314 
315  /**
316  * @return scale for alternate zone.
317  **********************************************************************/
318  property double AltScale { double get(); }
319  ///@}
320 
321  /** \name String representations of the GeoCoords object
322  **********************************************************************/
323  ///@{
324  /**
325  * String representation with latitude and longitude as signed decimal
326  * degrees.
327  *
328  * @param[in] prec precision (relative to about 1m).
329  * @param[in] swaplatlong if true give longitude first (default = false)
330  * @exception std::bad_alloc if memory for the string can't be allocated.
331  * @return decimal latitude/longitude string representation.
332  *
333  * Precision specifies accuracy of representation as follows:
334  * - prec = &minus;5 (min), 1&deg;
335  * - prec = 0, 10<sup>&minus;5</sup>&deg; (about 1m)
336  * - prec = 3, 10<sup>&minus;8</sup>&deg;
337  * - prec = 9 (max), 10<sup>&minus;14</sup>&deg;
338  **********************************************************************/
339  System::String^ GeoRepresentation(int prec, bool swaplatlong );
340 
341  /**
342  * String representation with latitude and longitude as degrees, minutes,
343  * seconds, and hemisphere.
344  *
345  * @param[in] prec precision (relative to about 1m)
346  * @param[in] swaplatlong if true give longitude first (default = false)
347  * @param[in] dmssep if non-null, use as the DMS separator character
348  * (instead of d, ', &quot; delimiters).
349  * @exception std::bad_alloc if memory for the string can't be allocated.
350  * @return DMS latitude/longitude string representation.
351  *
352  * Precision specifies accuracy of representation as follows:
353  * - prec = &minus;5 (min), 1&deg;
354  * - prec = &minus;4, 0.1&deg;
355  * - prec = &minus;3, 1'
356  * - prec = &minus;2, 0.1'
357  * - prec = &minus;1, 1&quot;
358  * - prec = 0, 0.1&quot; (about 3m)
359  * - prec = 1, 0.01&quot;
360  * - prec = 10 (max), 10<sup>&minus;11</sup>&quot;
361  **********************************************************************/
362  System::String^ DMSRepresentation(int prec, bool swaplatlong,
363  char dmssep );
364 
365  /**
366  * MGRS string.
367  *
368  * @param[in] prec precision (relative to about 1m).
369  * @exception std::bad_alloc if memory for the string can't be allocated.
370  * @return MGRS string.
371  *
372  * This gives the coordinates of the enclosing grid square with size given
373  * by the precision. Thus 38N 444180 3684790 converted to a MGRS
374  * coordinate at precision &minus;2 (100m) is 38SMB441847 and not
375  * 38SMB442848. \e prec specifies the precision of the MGRS string as
376  * follows:
377  * - prec = &minus;5 (min), 100km
378  * - prec = &minus;4, 10km
379  * - prec = &minus;3, 1km
380  * - prec = &minus;2, 100m
381  * - prec = &minus;1, 10m
382  * - prec = 0, 1m
383  * - prec = 1, 0.1m
384  * - prec = 6 (max), 1&mu;m
385  **********************************************************************/
386  System::String^ MGRSRepresentation(int prec);
387 
388  /**
389  * UTM/UPS string.
390  *
391  * @param[in] prec precision (relative to about 1m)
392  * @param[in] abbrev if true (the default) use abbreviated (n/s) notation
393  * for hemisphere; otherwise spell out the hemisphere (north/south)
394  * @exception std::bad_alloc if memory for the string can't be allocated.
395  * @return UTM/UPS string representation: zone designator, easting, and
396  * northing.
397  *
398  * Precision specifies accuracy of representation as follows:
399  * - prec = &minus;5 (min), 100km
400  * - prec = &minus;3, 1km
401  * - prec = 0, 1m
402  * - prec = 3, 1mm
403  * - prec = 6, 1&mu;m
404  * - prec = 9 (max), 1nm
405  **********************************************************************/
406  System::String^ UTMUPSRepresentation(int prec, bool abbrev);
407 
408  /**
409  * UTM/UPS string with hemisphere override.
410  *
411  * @param[in] northp hemisphere override
412  * @param[in] prec precision (relative to about 1m)
413  * @param[in] abbrev if true (the default) use abbreviated (n/s) notation
414  * for hemisphere; otherwise spell out the hemisphere (north/south)
415  * @exception GeographicErr if the hemisphere override attempts to change
416  * UPS N to UPS S or vice versa.
417  * @exception std::bad_alloc if memory for the string can't be allocated.
418  * @return UTM/UPS string representation: zone designator, easting, and
419  * northing.
420  **********************************************************************/
421  System::String^ UTMUPSRepresentation(bool northp, int prec, bool abbrev);
422 
423  /**
424  * MGRS string for the alternate zone. See GeoCoords::MGRSRepresentation.
425  *
426  * @param[in] prec precision (relative to about 1m).
427  * @exception std::bad_alloc if memory for the string can't be allocated.
428  * @return MGRS string.
429  **********************************************************************/
430  System::String^ AltMGRSRepresentation(int prec);
431 
432  /**
433  * UTM/UPS string for the alternate zone. See
434  * GeoCoords::UTMUPSRepresentation.
435  *
436  * @param[in] prec precision (relative to about 1m)
437  * @param[in] abbrev if true (the default) use abbreviated (n/s) notation
438  * for hemisphere; otherwise spell out the hemisphere (north/south)
439  * @exception std::bad_alloc if memory for the string can't be allocated.
440  * @return UTM/UPS string representation: zone designator, easting, and
441  * northing.
442  **********************************************************************/
443  System::String^ AltUTMUPSRepresentation(int prec, bool abbrev);
444 
445  /**
446  * UTM/UPS string for the alternate zone, with hemisphere override.
447  *
448  * @param[in] northp hemisphere override
449  * @param[in] prec precision (relative to about 1m)
450  * @param[in] abbrev if true (the default) use abbreviated (n/s) notation
451  * for hemisphere; otherwise spell out the hemisphere (north/south)
452  * @exception GeographicErr if the hemisphere override attempts to change
453  * UPS n to UPS s or vice verse.
454  * @exception std::bad_alloc if memory for the string can't be allocated.
455  * @return UTM/UPS string representation: zone designator, easting, and
456  * northing.
457  **********************************************************************/
458  System::String^ AltUTMUPSRepresentation(bool northp, int prec, bool abbrev);
459  ///@}
460 
461  /** \name Inspector functions
462  **********************************************************************/
463  ///@{
464  /**
465  * @return \e a the equatorial radius of the WGS84 ellipsoid (meters).
466  *
467  * (The WGS84 value is returned because the UTM and UPS projections are
468  * based on this ellipsoid.)
469  **********************************************************************/
470  property double MajorRadius { double get(); }
471 
472  /**
473  * @return \e f the flattening of the WGS84 ellipsoid.
474  *
475  * (The WGS84 value is returned because the UTM and UPS projections are
476  * based on this ellipsoid.)
477  **********************************************************************/
478  property double Flattening { double get(); }
479  ///@}
480  };
481 } //namespace NETGeographicLib
System::String^ AltMGRSRepresentation(int prec)
System::String^ DMSRepresentation(int prec, bool swaplatlong, char dmssep)
void Reset(System::String^ s, bool centerp, bool swaplatlong)
.NET wrapper for GeographicLib::GeoCoords.
Definition: GeoCoords.h:55
System::String^ GeoRepresentation(int prec, bool swaplatlong)
System::String^ UTMUPSRepresentation(int prec, bool abbrev)
System::String^ AltUTMUPSRepresentation(int prec, bool abbrev)
System::String^ MGRSRepresentation(int prec)