GeographicLib
1.21
|
Conversion between geographic coordinates. More...
#include <GeographicLib/GeoCoords.hpp>
Public Member Functions | |
Initializing the GeoCoords object | |
GeoCoords () throw () | |
GeoCoords (const std::string &s, bool centerp=true, bool swaplatlong=false) | |
GeoCoords (real latitude, real longitude, int zone=UTMUPS::STANDARD) | |
GeoCoords (int zone, bool northp, real easting, real northing) | |
void | Reset (const std::string &s, bool centerp=true, bool swaplatlong=false) |
void | Reset (real latitude, real longitude, int zone=UTMUPS::STANDARD) |
void | Reset (int zone, bool northp, real easting, real northing) |
Querying the GeoCoords object | |
Math::real | Latitude () const throw () |
Math::real | Longitude () const throw () |
Math::real | Easting () const throw () |
Math::real | Northing () const throw () |
Math::real | Convergence () const throw () |
Math::real | Scale () const throw () |
bool | Northp () const throw () |
char | Hemisphere () const throw () |
int | Zone () const throw () |
Setting and querying the alternate zone | |
void | SetAltZone (int zone=UTMUPS::STANDARD) const |
int | AltZone () const throw () |
Math::real | AltEasting () const throw () |
Math::real | AltNorthing () const throw () |
Math::real | AltConvergence () const throw () |
Math::real | AltScale () const throw () |
String representations of the GeoCoords object | |
std::string | GeoRepresentation (int prec=0, bool swaplatlong=false) const |
std::string | DMSRepresentation (int prec, bool swaplatlong, char dmssep) const |
std::string | DMSRepresentation (int prec=0, bool swaplatlong=false) 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 |
Inspector functions | |
Math::real | MajorRadius () const throw () |
Math::real | Flattening () const throw () |
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.
Example of use:
// Example of using the GeographicLib::GeoCoords class // $Id: 3f9c326bb5293db26a153e6f5eab165146899a9e $ #include <iostream> #include <exception> #include <string> #include <GeographicLib/GeoCoords.hpp> using namespace std; using namespace GeographicLib; int main() { try { // Miscellaneous conversions double lat = 33.3, lon = 44.4; GeoCoords c(lat, lon); cout << c.MGRSRepresentation(-3) << "\n"; c.Reset("18TWN0050"); cout << c.DMSRepresentation() << "\n"; cout << c.Latitude() << " " << c.Longitude() << "\n"; c.Reset("1d38'W 55d30'N"); cout << c.GeoRepresentation() << "\n"; } catch (const exception& e) { cerr << "Caught exception: " << e.what() << "\n"; return 1; } return 0; }
GeoConvert is a command-line utility providing access to the functionality of GeoCoords.
GeographicLib::GeoCoords::GeoCoords | ( | ) | throw () [inline] |
The default constructor is equivalent to latitude = 90o, longitude = 0o.
Definition at line 78 of file GeoCoords.hpp.
GeographicLib::GeoCoords::GeoCoords | ( | const std::string & | s, |
bool | centerp = true , |
||
bool | swaplatlong = false |
||
) | [inline, explicit] |
Construct from a string.
[in] | s | 1-element, 2-element, or 3-element string representation of the position. |
[in] | centerp | governs the interpretation of MGRS coordinates (see below). |
[in] | swaplatlong | governs the interpretation of geographic coordinates (see below). |
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
The following inputs are approximately the same (Ar Ramadi Bridge, Iraq)
Latitude and Longitude parsing. Latitude precedes longitude, unless a N, S, E, W hemisphere designator is used on one or both coordinates. If swaplatlong = true (default is false), then longitude precedes latitude in the absence of a hemisphere designator. Thus (with swaplatlong = false)
are all the same position. The coordinates may be given in decimal degrees, degrees and decimal minutes, degrees, minutes, seconds, etc. Use d, ', and " to mark off the degrees, minutes and seconds. Alternatively, use : to separate these components. Thus
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.). If centerp = true (the default), the center of this square is then taken to be the precise position; thus:
Otherwise, the "south-west" corner of the square is used, i.e.,
Definition at line 169 of file GeoCoords.hpp.
GeographicLib::GeoCoords::GeoCoords | ( | real | latitude, |
real | longitude, | ||
int | zone = UTMUPS::STANDARD |
||
) | [inline] |
Construct from geographic coordinates.
[in] | latitude | (degrees). |
[in] | longitude | (degrees). |
[in] | zone | if specified, force the UTM/UPS representation to use a specified zone using the rules given in UTMUPS::zonespec. |
Definition at line 181 of file GeoCoords.hpp.
GeographicLib::GeoCoords::GeoCoords | ( | int | zone, |
bool | northp, | ||
real | easting, | ||
real | northing | ||
) | [inline] |
Construct from UTM/UPS coordinates.
[in] | zone | UTM zone (zero means UPS). |
[in] | northp | hemisphere (true means north, false means south). |
[in] | easting | (meters). |
[in] | northing | (meters). |
Definition at line 193 of file GeoCoords.hpp.
void GeographicLib::GeoCoords::Reset | ( | const std::string & | s, |
bool | centerp = true , |
||
bool | swaplatlong = false |
||
) |
Reset the location from a string. See GeoCoords(const std::string& s, bool centerp, bool swaplatlong).
Definition at line 27 of file GeoCoords.cpp.
Referenced by main().
void GeographicLib::GeoCoords::Reset | ( | real | latitude, |
real | longitude, | ||
int | zone = UTMUPS::STANDARD |
||
) | [inline] |
Reset the location in terms of geographic coordinates. See GeoCoords(real latitude, real longitude, int zone).
Definition at line 208 of file GeoCoords.hpp.
References GeographicLib::UTMUPS::Forward().
void GeographicLib::GeoCoords::Reset | ( | int | zone, |
bool | northp, | ||
real | easting, | ||
real | northing | ||
) | [inline] |
Reset the location in terms of UPS/UPS coordinates. See GeoCoords(int zone, bool northp, real easting, real northing).
Definition at line 223 of file GeoCoords.hpp.
References GeographicLib::UTMUPS::Reverse().
Math::real GeographicLib::GeoCoords::Latitude | ( | ) | const throw () [inline] |
Math::real GeographicLib::GeoCoords::Longitude | ( | ) | const throw () [inline] |
Math::real GeographicLib::GeoCoords::Easting | ( | ) | const throw () [inline] |
Definition at line 251 of file GeoCoords.hpp.
Math::real GeographicLib::GeoCoords::Northing | ( | ) | const throw () [inline] |
Definition at line 256 of file GeoCoords.hpp.
Math::real GeographicLib::GeoCoords::Convergence | ( | ) | const throw () [inline] |
Definition at line 261 of file GeoCoords.hpp.
Math::real GeographicLib::GeoCoords::Scale | ( | ) | const throw () [inline] |
Definition at line 266 of file GeoCoords.hpp.
bool GeographicLib::GeoCoords::Northp | ( | ) | const throw () [inline] |
Definition at line 271 of file GeoCoords.hpp.
char GeographicLib::GeoCoords::Hemisphere | ( | ) | const throw () [inline] |
Definition at line 276 of file GeoCoords.hpp.
int GeographicLib::GeoCoords::Zone | ( | ) | const throw () [inline] |
Definition at line 281 of file GeoCoords.hpp.
void GeographicLib::GeoCoords::SetAltZone | ( | int | zone = UTMUPS::STANDARD | ) | const [inline] |
Specify alternate zone number.
[in] | zone | zone number for the alternate representation. |
See UTMUPS::zonespec for more information on the interpretation of zone. Note that zone == UTMUPS::STANDARD (the default) use the standard UPS or UTM zone, UTMUPS::MATCH does nothing retaining the existing alternate representation. Before this is called the alternate zone is the input zone.
Definition at line 299 of file GeoCoords.hpp.
References GeographicLib::UTMUPS::MATCH, GeographicLib::UTMUPS::StandardZone(), and GeographicLib::UTMUPS::Forward().
int GeographicLib::GeoCoords::AltZone | ( | ) | const throw () [inline] |
Definition at line 317 of file GeoCoords.hpp.
Math::real GeographicLib::GeoCoords::AltEasting | ( | ) | const throw () [inline] |
Definition at line 322 of file GeoCoords.hpp.
Math::real GeographicLib::GeoCoords::AltNorthing | ( | ) | const throw () [inline] |
Definition at line 327 of file GeoCoords.hpp.
Math::real GeographicLib::GeoCoords::AltConvergence | ( | ) | const throw () [inline] |
Definition at line 332 of file GeoCoords.hpp.
Math::real GeographicLib::GeoCoords::AltScale | ( | ) | const throw () [inline] |
Definition at line 337 of file GeoCoords.hpp.
string GeographicLib::GeoCoords::GeoRepresentation | ( | int | prec = 0 , |
bool | swaplatlong = false |
||
) | const |
String representation with latitude and longitude as signed decimal degrees.
[in] | prec | precision (relative to about 1m). |
[in] | swaplatlong | if true give longitude first (default = false) |
Precision specifies accuracy of representation as follows:
Definition at line 70 of file GeoCoords.cpp.
string GeographicLib::GeoCoords::DMSRepresentation | ( | int | prec, |
bool | swaplatlong, | ||
char | dmssep | ||
) | const |
String representation with latitude and longitude as degrees, minutes, seconds, and hemisphere.
[in] | prec | precision (relative to about 1m) |
[in] | swaplatlong | if true give longitude first (default = false) |
[in] | dmssep | if non-null, use as the DMS separator character (instead of d, ', " delimiters). |
Precision specifies accuracy of representation as follows:
Definition at line 88 of file GeoCoords.cpp.
string GeographicLib::GeoCoords::DMSRepresentation | ( | int | prec = 0 , |
bool | swaplatlong = false |
||
) | const |
String representation with latitude and longitude as degrees, minutes, seconds, and hemisphere.
[in] | prec | precision (relative to about 1m) |
[in] | swaplatlong | if true give longitude first (default = false) |
COMPATIBILITY NOTE: This function calls DMSRepresentation(int, bool, char) const with a 3rd argument of char(0). At some point, DMSRepresentation(int, bool) const and will be withdrawn and the interface to DMSRepresentation(int, bool, char) const changed so that its arguments have default values. This will preserve source-level compatibility.
Definition at line 97 of file GeoCoords.cpp.
string GeographicLib::GeoCoords::MGRSRepresentation | ( | int | prec = 0 | ) | const |
MGRS string.
[in] | prec | precision (relative to about 1m). |
This gives the coordinates of the enclosing grid square with size given by the precision. Thus 38N 444180 3684790 converted to a MGRS coordinate at precision -2 (100m) is 38SMB441847 and not 38SMB442848. prec specifies the precision of the MGRS string as follows:
Definition at line 100 of file GeoCoords.cpp.
string GeographicLib::GeoCoords::UTMUPSRepresentation | ( | int | prec = 0 | ) | const |
UTM/UPS string.
[in] | prec | precision (relative to about 1m) |
Precision specifies accuracy of representation as follows:
Definition at line 138 of file GeoCoords.cpp.
string GeographicLib::GeoCoords::AltMGRSRepresentation | ( | int | prec = 0 | ) | const |
MGRS string for the alternate zone. See GeoCoords::MGRSRepresentation.
Definition at line 108 of file GeoCoords.cpp.
string GeographicLib::GeoCoords::AltUTMUPSRepresentation | ( | int | prec = 0 | ) | const |
UTM/UPS string for the alternate zone. See GeoCoords::UTMUPSRepresentation.
Definition at line 144 of file GeoCoords.cpp.
Math::real GeographicLib::GeoCoords::MajorRadius | ( | ) | const throw () [inline] |
(The WGS84 value is returned because the UTM and UPS projections are based on this ellipsoid.)
Definition at line 459 of file GeoCoords.hpp.
References GeographicLib::UTMUPS::MajorRadius().
Math::real GeographicLib::GeoCoords::Flattening | ( | ) | const throw () [inline] |
(The WGS84 value is returned because the UTM and UPS projections are based on this ellipsoid.)
Definition at line 467 of file GeoCoords.hpp.
References GeographicLib::UTMUPS::Flattening().