Public Member Functions
GeographicLib::GeoCoords Class Reference

Conversion between geographic coordinates. More...

#include <GeographicLib/GeoCoords.hpp>

List of all members.

Public Member Functions

 GeoCoords () throw ()
 GeoCoords (const std::string &s)
 GeoCoords (double latitude, double longitude, int zone=-1)
 GeoCoords (int zone, bool northp, double easting, double northing)
void Reset (const std::string &s)
void Reset (double latitude, double longitude, int zone=-1)
void Reset (int zone, bool northp, double easting, double northing)
double Latitude () const throw ()
double Longitude () const throw ()
double Easting () const throw ()
double Northing () const throw ()
double Convergence () const throw ()
double Scale () const throw ()
bool Northp () const throw ()
char Hemisphere () const throw ()
int Zone () const throw ()
void SetAltZone (int zone=-1) const
int AltZone () const throw ()
double AltEasting () const throw ()
double AltNorthing () const throw ()
double AltConvergence () const throw ()
double AltScale () const throw ()
std::string GeoRepresentation (int prec=0) const
std::string DMSRepresentation (int prec=0) const
std::string MGRSRepresentation (int prec=0) const
std::string UTMUPSRepresentation (int prec=0) const
std::string AltMGRSRepresentation (int prec=0) const
std::string AltUTMUPSRepresentation (int prec=0) const

Detailed Description

Conversion between geographic coordinates.

This class stores a geographic position which may be set via the constructors or Reset via

The state consists of the latitude and longitude and the supplied UTM or UPS coordinates (possibly derived from the MGRS coordinates). If latitude and longitude were given then the UTM/UPS coordinates follows the standard conventions.

The mutable state consists of the UTM or UPS coordinates for a alternate zone. A method SetAltZone is provided to set the alternate UPS/UTM zone.

Methods are provided to return the geographic coordinates, the input UTM or UPS coordinates (and associated meridian convergence and scale), or alternate UTM or UPS coordinates (and their associated meridian convergence and scale).

Once the input string has been parsed, you can print the result out in any of the formats, decimal degrees, degrees minutes seconds, MGRS, UTM/UPS.


Constructor & Destructor Documentation

GeographicLib::GeoCoords::GeoCoords ( ) throw () [inline]

The default contructor is equivalent to latitude = 90o, longitude = 0o.

Definition at line 79 of file GeoCoords.hpp.

GeographicLib::GeoCoords::GeoCoords ( const std::string &  s) [inline]

Parse as a string and interpret it as a geographic position. The input string is broken into space (or comma) separated pieces and Basic decision on which format is based on number of components

  1. MGRS
  2. "Lat Long" or "Long Lat"
  3. "Zone Easting Northing" or "Easting Northing Zone"

The following inputs are approximately the same (Ar Ramadi Bridge, Iraq)

  • Latitude and Longitude
    • 33.44 43.27
    • N33d26.4' E43d16.2'
    • 43d16'12"E 33d26'24"N
  • MGRS
    • 38SLC301
    • 38SLC391014
    • 38SLC3918701405
    • 37SHT9708
  • UTM
    • 38N 339188 3701405
    • 897039 3708229 37N

Latitude and Longitude parsing. Latitude precedes longitude, unless a N, S, E, W hemisphere designator is used on one or both coordinates. Thus

  • 40 -75
  • N40 W75
  • -75 N40
  • 75W 40N
  • E-75 -40S

are all the same position. The coodinates may be given in decimal degrees, degrees and decimal minutes, degrees, minutes, seconds, etc. Use d, ', and " to make off the degrees, minutes and seconds. Thus - 40d30'30"

  • 40d30'30
  • 40d30.5'
  • 40d30.5
  • 40.508333333

all specify the same angle. The leading sign applies to all components so -1d30 is -(1+30/60) = -1.5. Latitudes must be in the range [-90, 90] and longitudes in the range [-180, 360]. Internally longitudes are reduced to the range [-180, 180).

UTM/UPS parsing. For UTM zones (-80 <= Lat <= 84), the zone designator is made up of a zone number (for 1 to 60) and a hemisphere letter (N or S), e.g., 38N. The latitude zone designer ([C–M] in the southern hemisphere and [N–X] in the northern) should NOT be used. (This is part of the MGRS coordinate.) The zone designator for the poles (where UPS is employed) is a hemisphere letter by itself, i.e., N or S.

MGRS parsing interprets the grid references as square area at the specified precision (1m, 10m, 100m, etc.). The center of this square is then taken to be the precise position. Thus:

  • 38SMB = 38N 450000 3650000
  • 38SMB4484 = 38N 444500 3684500
  • 38SMB44148470 = 38N 444145 3684705

Definition at line 148 of file GeoCoords.hpp.

References Reset().

GeographicLib::GeoCoords::GeoCoords ( double  latitude,
double  longitude,
int  zone = -1 
) [inline]

Specify the location in terms of latitude (degrees) and longitude (degrees). Use zone to force the UTM/UPS representation to use a specified zone (zone = 0 means UPS). Omitting the third argument causes the standard zone to be used.

Definition at line 156 of file GeoCoords.hpp.

References Reset().

GeographicLib::GeoCoords::GeoCoords ( int  zone,
bool  northp,
double  easting,
double  northing 
) [inline]

Specify the location in terms of UPS/UPS zone (zero means UPS), hemisphere northp (false means south, true means north), easting (meters) and northing (meters).

Definition at line 165 of file GeoCoords.hpp.

References Reset().


Member Function Documentation

void GeographicLib::GeoCoords::Reset ( const std::string &  s)

Reset the location as a 1-element, 2-element, or 3-element string. See GeoCoords(const string& s).

Definition at line 28 of file GeoCoords.cpp.

References GeographicLib::MGRS::Reverse(), GeographicLib::UTMUPS::Reverse(), GeographicLib::DMS::DecodeLatLon(), and GeographicLib::UTMUPS::Forward().

Referenced by main(), and GeoCoords().

void GeographicLib::GeoCoords::Reset ( double  latitude,
double  longitude,
int  zone = -1 
) [inline]

Reset the location in terms of latitude and longitude. See GeoCoords(double latitude, double longitude, int zone).

Definition at line 179 of file GeoCoords.hpp.

References GeographicLib::UTMUPS::Forward().

void GeographicLib::GeoCoords::Reset ( int  zone,
bool  northp,
double  easting,
double  northing 
) [inline]

Reset the location in terms of UPS/UPS zone, hemisphere northp, easting, and northing. See GeoCoords(int zone, bool northp, double easting, double northing).

Definition at line 195 of file GeoCoords.hpp.

References GeographicLib::UTMUPS::Reverse().

double GeographicLib::GeoCoords::Latitude ( ) const throw () [inline]

Return latitude (degrees)

Definition at line 209 of file GeoCoords.hpp.

double GeographicLib::GeoCoords::Longitude ( ) const throw () [inline]

Return longitude (degrees)

Definition at line 214 of file GeoCoords.hpp.

double GeographicLib::GeoCoords::Easting ( ) const throw () [inline]

Return easting (meters)

Definition at line 219 of file GeoCoords.hpp.

double GeographicLib::GeoCoords::Northing ( ) const throw () [inline]

Return northing (meters)

Definition at line 224 of file GeoCoords.hpp.

double GeographicLib::GeoCoords::Convergence ( ) const throw () [inline]

Return meridian convergence (degrees) for the UTM/UPS projection.

Definition at line 229 of file GeoCoords.hpp.

double GeographicLib::GeoCoords::Scale ( ) const throw () [inline]

Return scale for the UTM/UPS projection.

Definition at line 234 of file GeoCoords.hpp.

bool GeographicLib::GeoCoords::Northp ( ) const throw () [inline]

Return hemisphere (false means south, true means north).

Definition at line 239 of file GeoCoords.hpp.

char GeographicLib::GeoCoords::Hemisphere ( ) const throw () [inline]

Return hemisphere letter N or S.

Definition at line 244 of file GeoCoords.hpp.

int GeographicLib::GeoCoords::Zone ( ) const throw () [inline]

Return the zone corresponding to the input (return 0 for UPS).

Definition at line 249 of file GeoCoords.hpp.

void GeographicLib::GeoCoords::SetAltZone ( int  zone = -1) const [inline]

Set the zone (default, -1, means use the standard zone) for the alternate representation. Before this is called the alternate zone is the input zone.

Definition at line 256 of file GeoCoords.hpp.

References GeographicLib::UTMUPS::StandardZone(), and GeographicLib::UTMUPS::Forward().

Referenced by main().

int GeographicLib::GeoCoords::AltZone ( ) const throw () [inline]

Returns the current alternate zone (return 0 for UPS).

Definition at line 272 of file GeoCoords.hpp.

double GeographicLib::GeoCoords::AltEasting ( ) const throw () [inline]

Return easting (meters) for alternate zone.

Definition at line 277 of file GeoCoords.hpp.

double GeographicLib::GeoCoords::AltNorthing ( ) const throw () [inline]

Return northing (meters) for alternate zone.

Definition at line 282 of file GeoCoords.hpp.

double GeographicLib::GeoCoords::AltConvergence ( ) const throw () [inline]

Return meridian convergence (degrees) for altermate zone.

Definition at line 287 of file GeoCoords.hpp.

Referenced by main().

double GeographicLib::GeoCoords::AltScale ( ) const throw () [inline]

Return scale for altermate zone.

Definition at line 292 of file GeoCoords.hpp.

Referenced by main().

string GeographicLib::GeoCoords::GeoRepresentation ( int  prec = 0) const

Return string with latitude and longitude as signed decimal degrees. Precision prec specifies accuracy of representation as follows:

  • prec = -5 (min), 1d
  • prec = 0, 10-5d (about 1m)
  • prec = 3, 10-8d
  • prec = 9 (max), 10-14d

Definition at line 101 of file GeoCoords.cpp.

Referenced by main().

string GeographicLib::GeoCoords::DMSRepresentation ( int  prec = 0) const

Return string with latitude and longitude as degrees, minutes, seconds, and hemisphere. Precision prec specifies accuracy of representation as follows:

  • prec = -5 (min), 1d
  • prec = -4, 0.1d
  • prec = -3, 1'
  • prec = -2, 0.1'
  • prec = -1, 1" - prec = 0, 0.1" (about 3m)
  • prec = 1, 0.01" - prec = 10 (max), 10<sup>-11</sup>"

Definition at line 109 of file GeoCoords.cpp.

References GeographicLib::DMS::Encode(), GeographicLib::DMS::LATITUDE, and GeographicLib::DMS::LONGITUDE.

Referenced by main().

string GeographicLib::GeoCoords::MGRSRepresentation ( int  prec = 0) const

Return MGRS string. This gives the coordinates of the enclosing grid square with size given by the precision prec. Thus 38N 444180 3684790 converted to a MGRS coordinate at precision -2 (100m) is 38SMB441847 and not 38SMB442848. Precision prec specifies the precision of the MSGRS string as follows:

  • prec = -5 (min), 100km
  • prec = -4, 10km
  • prec = -3, 1km
  • prec = -2, 100m
  • prec = -1, 10m
  • prec = 0, 1m
  • prec = 1, 0.1m
  • prec = 6 (max), 1um

Definition at line 115 of file GeoCoords.cpp.

References GeographicLib::MGRS::Forward().

string GeographicLib::GeoCoords::UTMUPSRepresentation ( int  prec = 0) const

Return string consisting of UTM/UPS zone designator, easting, and northing, Precision prec specifies accuracy of representation as follows:

  • prec = -5 (min), 100km
  • prec = -3, 1km
  • prec = 0, 1m
  • prec = 3, 1mm
  • prec = 6, 1um
  • prec = 9 (max), 1nm

Definition at line 153 of file GeoCoords.cpp.

string GeographicLib::GeoCoords::AltMGRSRepresentation ( int  prec = 0) const

Return MGRS string using alternative zone. See MGRSRepresentation for the interpretation of prec.

Definition at line 123 of file GeoCoords.cpp.

References GeographicLib::MGRS::Forward().

Referenced by main().

string GeographicLib::GeoCoords::AltUTMUPSRepresentation ( int  prec = 0) const

Return string consisting of alternate UTM/UPS zone designator, easting, and northing. See UTMUPSRepresentation for the interpretation of prec.

Definition at line 159 of file GeoCoords.cpp.

Referenced by main().


The documentation for this class was generated from the following files: