A static class to handle geographic algorithms. This class offers methods to handle lat/lon coordinates, to transform lat/lon coordinates, to compute distances on a sphere or to convert between coordinate systems.
#include <CoordsAlgorithms.h>
Public Types | |
enum | ELLIPSOIDS_NAMES { E_WGS84 , E_WGS72 , E_GRS80 , E_AIRY , E_INTL1924 , E_CLARKE1880 , E_CLARKE1866 , E_GRS67 , E_EVEREST1830 , E_IERS2003 , E_KRASSOVSKY , NONE } |
Keywords for selecting an ellipsoid to use. More... | |
Static Public Member Functions | |
static double | dms_to_decimal (const std::string &dms) |
Parse a latitude or longitude It can be formatted as any of the following examples: More... | |
static std::string | decimal_to_dms (const double &decimal) |
Converts a decimal latitude or longitude to degrees, minutes, seconds It formats its arguments as in the following example: 46°48'03". More... | |
static void | parseLatLon (const std::string &coordinates, double &lat, double &lon) |
Parse a latitude-longitude pair It can be formatted as any of the following examples: More... | |
static std::string | printLatLon (const double &latitude, const double &longitude) |
Print a nicely formatted lat/lon in degrees, minutes, seconds. More... | |
static double | lat_degree_lenght (const double &latitude) |
Lenght of one degree of latitude This returns the lenght in meters of one degree of latitude around the given latitude (ie: latitude-.5, latitude+.5). See https://en.wikipedia.org/wiki/Latitude#The_length_of_a_degree_of_latitude. More... | |
static double | lon_degree_lenght (const double &latitude) |
Lenght of one degree of longitude This returns the lenght in meters of one degree of longitude around the given latitude (ie: latitude-.5, latitude+.5). See https://en.wikipedia.org/wiki/Latitude#The_length_of_a_degree_of_latitude. More... | |
static bool | isUTM (const int &epsg) |
Does a given epsg code describe UTM coordinates? More... | |
static short int | str_to_EPSG (const std::string &coordsystem, const std::string &coordparam) |
returns the epsg code matching a provided string representation For example, when given "CH1903" with empty coordparam, it will return "21781". For "LOCAL" coordinates, it returns IOUtils::snodata. More... | |
static void | EPSG_to_str (const int &epsg, std::string &coordsystem, std::string &coordparam) |
Build the string representation for a given EPSG code. More... | |
static void | rotatedToTrueLatLon (const double &lat_N, const double &lon_N, const double &lat_rot, const double &lon_rot, double &lat_true, double &lon_true) |
Convert rotated lat/lon into geographic lat/lon Rotated coordinates are created by moving the North pole by a given offset along latitude and longitude. The goal is to put the equator through the center of the domain of interest, so a lat/lon grid can easily be approximated by a tangential cartesian coordinate system. (see http://www.cosmo-model.org/content/model/documentation/core/default.htm, part I, chapter 3.3 for more) More... | |
static void | trueLatLonToRotated (const double &lat_N, const double &lon_N, const double &lat_true, const double &lon_true, double &lat_rot, double &lon_rot) |
Convert geographic lat/lon into rotated lat/lon Rotated coordinates are created by moving the North pole by a given offset along latitude and longitude. The goal is to put the equator through the center of the domain of interest, so a lat/lon grid can easily be approximated by a tangential cartesian coordinate system. (see http://www.cosmo-model.org/content/model/documentation/core/default.htm, part I, chapter 3.3 for more) More... | |
static void | Molodensky (const double &lat_in, const double &lon_in, const double &alt_in, const ELLIPSOIDS_NAMES &ellipsoid_in, double &lat_out, double &lon_out, double &alt_out, const ELLIPSOIDS_NAMES &ellipsoid_out, const double &delta_x=0., const double &delta_y=0., const double &delta_z=0.) |
Molodensky datum transformation. This converts lat/lon from one datum to another (for example, NAD27 to WGS84, or spherical to WGS84). The ellipsoid names (see CoordsAlgorithms::ELLIPSOIDS_NAMES) and delta_x/y/z that describe the datums must be provided (if no deltas are provided, they are assumed to be zeroes). For more information, see https://en.wikipedia.org/wiki/Geographic_coordinate_conversion#Molodensky_transformation or http://www.colorado.edu/geography/gcraft/notes/datum/gif/molodens.gif. More... | |
static double | cosineDistance (const double &lat1, const double &lon1, const double &lat2, const double &lon2, double &alpha) |
Spherical law of cosine Distance calculation between points in WGS84 (decimal Lat/Long) See http://www.movable-type.co.uk/scripts/latlong.html for more. More... | |
static void | cosineInverse (const double &lat_ref, const double &lon_ref, const double &distance, const double &bearing, double &lat, double &lon) |
Spherical law of cosine Distance calculation between points in WGS84 (decimal Lat/Long) See http://www.movable-type.co.uk/scripts/latlong.html for more. More... | |
static double | VincentyDistance (const double &lat1, const double &lon1, const double &lat2, const double &lon2, double &alpha) |
Vincenty Distance calculation between points in WGS84 (decimal Lat/Long) See T. Vincenty, "Closed formulas for the direct and reverse geodetic problems", Journal of Geodesy, 51, 3, 1977, DOI:10.1007/BF02521599, see http://www.springerlink.com/content/y7108u6862473583 for more. More... | |
static void | VincentyInverse (const double &lat_ref, const double &lon_ref, const double &distance, const double &bearing, double &lat, double &lon) |
Vincenty Inverse calculation giving WGS84 (decimal Lat/Long) position given a start location (lat,lon) a distance and a bearing See T. Vincenty, "Closed formulas for the direct and reverse geodetic problems", Journal of Geodesy, 51, 3, 1977, DOI:10.1007/BF02521599, see http://www.springerlink.com/content/y7108u6862473583 for more. More... | |
static void | WGS84_to_CH1903 (const double &lat_in, const double &long_in, double &east_out, double &north_out) |
Coordinate conversion: from WGS84 Lat/Long to Swiss grid See https://www.swisstopo.admin.ch/de/karten-daten-online/calculation-services.html in the "Documents" section for more. More... | |
static void | CH1903_to_WGS84 (const double &east_in, const double &north_in, double &lat_out, double &long_out) |
Coordinate conversion: from Swiss grid to WGS84 Lat/Long See https://www.swisstopo.admin.ch/de/karten-daten-online/calculation-services.html in the "Documents" section for more. More... | |
static void | WGS84_to_UTM (const double &lat_in, double long_in, const std::string &coordparam, double &east_out, double &north_out) |
Coordinate conversion: from WGS84 Lat/Long to UTM grid. For more, see http://www.oc.nps.edu/oc2902w/maps/utmups.pdf, USGS Bulletin 1532 or http://earth-info.nga.mil/GandG/publications/tm8358.2/TM8358_2.pdf, http://www.uwgb.edu/dutchs/usefuldata/UTMFormulas.HTM or Chuck Gantz (http://www.gpsy.com/gpsinfo/geotoutm/). More... | |
static void | UTM_to_WGS84 (double east_in, double north_in, const std::string &coordparam, double &lat_out, double &long_out) |
Coordinate conversion: from UTM grid to WGS84 Lat/Long. For more, see http://www.oc.nps.edu/oc2902w/maps/utmups.pdf, USGS Bulletin 1532 or http://earth-info.nga.mil/GandG/publications/tm8358.2/TM8358_2.pdf, http://www.uwgb.edu/dutchs/usefuldata/UTMFormulas.HTM or Chuck Gantz (http://www.gpsy.com/gpsinfo/geotoutm/). More... | |
static void | WGS84_to_UPS (const double &lat_in, const double &long_in, const std::string &coordparam, double &east_out, double &north_out) |
Coordinate conversion: from WGS84 Lat/Long to Universal Polar Stereographic grid see J. Hager, J. Behensky, B. Drew, THE UNIVERSAL GRIDS: Universal Transverse Mercator (UTM) and Universal Polar Stereographic (UPS), 1989, Defense Mapping Agency, DMATM 8358.2. This is valid above latitudes 84N or above 80S. More... | |
static void | UPS_to_WGS84 (const double &east_in, const double &north_in, const std::string &coordparam, double &lat_out, double &long_out) |
Coordinate conversion: from Universal Polar Stereographic grid to WGS84 Lat/Long see J. Hager, J. Behensky, B. Drew, THE UNIVERSAL GRIDS: Universal Transverse Mercator (UTM) and Universal Polar Stereographic (UPS), 1989, Defense Mapping Agency, DMATM 8358.2. This is valid above latitudes 84N or above 80S. More... | |
static void | WGS84_to_PROJ (const double &lat_in, const double &long_in, const std::string &coordparam, double &east_out, double &north_out) |
Coordinate conversion: from WGS84 Lat/Long to proj parameters. More... | |
static void | PROJ_to_WGS84 (const double &east_in, const double &north_in, const std::string &coordparam, double &lat_out, double &long_out) |
Coordinate conversion: from proj parameters to WGS84 Lat/Long. More... | |
static int | getUTMZone (const double &latitude, const double &longitude, std::string &zone_out) |
static void | parseUTMZone (const std::string &zone_info, char &zoneLetter, short int &zoneNumber) |
Keywords for selecting an ellipsoid to use.
|
static |
Coordinate conversion: from Swiss grid to WGS84 Lat/Long See https://www.swisstopo.admin.ch/de/karten-daten-online/calculation-services.html in the "Documents" section for more.
[in] | east_in | easting coordinate (Swiss system) |
[in] | north_in | northing coordinate (Swiss system) |
[out] | lat_out | Decimal Latitude |
[out] | long_out | Decimal Longitude |
|
static |
Spherical law of cosine Distance calculation between points in WGS84 (decimal Lat/Long) See http://www.movable-type.co.uk/scripts/latlong.html for more.
[in] | lat1 | Decimal Latitude (const double&) |
[in] | lon1 | Decimal Longitude (const double&) |
[in] | lat2 | Decimal Latitude (const double&) |
[in] | lon2 | Decimal Longitude (const double&) |
[out] | alpha | average bearing |
|
static |
Spherical law of cosine Distance calculation between points in WGS84 (decimal Lat/Long) See http://www.movable-type.co.uk/scripts/latlong.html for more.
[in] | lat_ref | Decimal Latitude (const double&) |
[in] | lon_ref | Decimal Longitude (const double&) |
[in] | distance | Distance in meters (const double&) |
[in] | bearing | bearing in degrees, 0 being north (const double&) |
[out] | lat | Decimal latitude of target point (double&) |
[out] | lon | Decimal longitude of target point (double&) |
|
static |
Converts a decimal latitude or longitude to degrees, minutes, seconds It formats its arguments as in the following example: 46°48'03".
[in] | decimal | decimal coordinate to convert |
|
static |
Parse a latitude or longitude It can be formatted as any of the following examples:
[in] | dms | string containing the coordinate |
|
static |
Build the string representation for a given EPSG code.
[in] | epsg | epsg code |
[out] | coordsystem | string representation of the coordinate system |
[out] | coordparam | string representation of the optional coordinate system parameters (such as zone for utm, etc) |
|
static |
|
static |
Does a given epsg code describe UTM coordinates?
[in] | epsg | epsg code |
|
static |
Lenght of one degree of latitude This returns the lenght in meters of one degree of latitude around the given latitude (ie: latitude-.5, latitude+.5). See https://en.wikipedia.org/wiki/Latitude#The_length_of_a_degree_of_latitude.
[in] | latitude | latitude where to perform the computation |
|
static |
Lenght of one degree of longitude This returns the lenght in meters of one degree of longitude around the given latitude (ie: latitude-.5, latitude+.5). See https://en.wikipedia.org/wiki/Latitude#The_length_of_a_degree_of_latitude.
[in] | latitude | latitude where to perform the computation |
|
static |
Molodensky datum transformation. This converts lat/lon from one datum to another (for example, NAD27 to WGS84, or spherical to WGS84). The ellipsoid names (see CoordsAlgorithms::ELLIPSOIDS_NAMES) and delta_x/y/z that describe the datums must be provided (if no deltas are provided, they are assumed to be zeroes). For more information, see https://en.wikipedia.org/wiki/Geographic_coordinate_conversion#Molodensky_transformation or http://www.colorado.edu/geography/gcraft/notes/datum/gif/molodens.gif.
[in] | lat_in | input latitude (degrees) |
[in] | lon_in | input longitude (degrees) |
[in] | alt_in | input altitude above sea level |
[in] | ellipsoid_in | ellipsoid of the input datum (see CoordsAlgorithms::ELLIPSOIDS_NAMES) |
[out] | lat_out | output latitude (degrees) |
[out] | lon_out | output longitude (degrees) |
[out] | alt_out | output altitude above sea level |
[out] | ellipsoid_out | ellipsoid of the output datum (see CoordsAlgorithms::ELLIPSOIDS_NAMES) |
[in] | delta_x | Origin shift, x coordinate (default: 0) |
[in] | delta_y | Origin shift, y coordinate (default: 0) |
[in] | delta_z | Origin shift, z coordinate (default: 0) |
|
static |
Parse a latitude-longitude pair It can be formatted as any of the following examples:
[in] | coordinates | string containing the coordinates |
[out] | lat | parsed latitude |
[out] | lon | parsed longitude |
|
static |
|
static |
Print a nicely formatted lat/lon in degrees, minutes, seconds.
|
static |
Coordinate conversion: from proj parameters to WGS84 Lat/Long.
east_in | easting coordinate (Swiss system) | |
north_in | northing coordinate (Swiss system) | |
[in] | coordparam | Extra parameters necessary for the conversion (such as UTM zone, etc) |
lat_out | Decimal Latitude | |
long_out | Decimal Longitude |
|
static |
Convert rotated lat/lon into geographic lat/lon Rotated coordinates are created by moving the North pole by a given offset along latitude and longitude. The goal is to put the equator through the center of the domain of interest, so a lat/lon grid can easily be approximated by a tangential cartesian coordinate system. (see http://www.cosmo-model.org/content/model/documentation/core/default.htm, part I, chapter 3.3 for more)
[in] | lat_N | North pole latitude offset |
[in] | lon_N | North pole longitude offset |
[in] | lat_rot | rotated latitude |
[in] | lon_rot | rotated longitude |
[out] | lat_true | geographic latitude |
[out] | lon_true | geographic longitude |
|
static |
returns the epsg code matching a provided string representation For example, when given "CH1903" with empty coordparam, it will return "21781". For "LOCAL" coordinates, it returns IOUtils::snodata.
[in] | coordsystem | string representation of the coordinate system |
[in] | coordparam | string representation of the optional coordinate system parameters (such as zone for utm, etc) |
|
static |
Convert geographic lat/lon into rotated lat/lon Rotated coordinates are created by moving the North pole by a given offset along latitude and longitude. The goal is to put the equator through the center of the domain of interest, so a lat/lon grid can easily be approximated by a tangential cartesian coordinate system. (see http://www.cosmo-model.org/content/model/documentation/core/default.htm, part I, chapter 3.3 for more)
[in] | lat_N | North pole latitude offset |
[in] | lon_N | North pole longitude offset |
[in] | lat_true | geographic latitude |
[in] | lon_true | geographic longitude |
[out] | lat_rot | rotated latitude |
[out] | lon_rot | rotated longitude |
|
static |
Coordinate conversion: from Universal Polar Stereographic grid to WGS84 Lat/Long see J. Hager, J. Behensky, B. Drew, THE UNIVERSAL GRIDS: Universal Transverse Mercator (UTM) and Universal Polar Stereographic (UPS), 1989, Defense Mapping Agency, DMATM 8358.2. This is valid above latitudes 84N or above 80S.
[in] | east_in | easting coordinate (UTM) |
[in] | north_in | northing coordinate (UTM) |
[in] | coordparam | UPS zone, either "N" or "S" |
[out] | lat_out | Decimal Latitude |
[out] | long_out | Decimal Longitude |
|
static |
Coordinate conversion: from UTM grid to WGS84 Lat/Long. For more, see http://www.oc.nps.edu/oc2902w/maps/utmups.pdf, USGS Bulletin 1532 or http://earth-info.nga.mil/GandG/publications/tm8358.2/TM8358_2.pdf, http://www.uwgb.edu/dutchs/usefuldata/UTMFormulas.HTM or Chuck Gantz (http://www.gpsy.com/gpsinfo/geotoutm/).
[in] | east_in | easting coordinate (UTM) |
[in] | north_in | northing coordinate (UTM) |
[in] | coordparam | UTM zone of the easting/northing |
[out] | lat_out | Decimal Latitude |
[out] | long_out | Decimal Longitude |
|
static |
Vincenty Distance calculation between points in WGS84 (decimal Lat/Long) See T. Vincenty, "Closed formulas for the direct and reverse geodetic problems", Journal of Geodesy, 51, 3, 1977, DOI:10.1007/BF02521599, see http://www.springerlink.com/content/y7108u6862473583 for more.
[in] | lat1 | Decimal Latitude (const double&) |
[in] | lon1 | Decimal Longitude (const double&) |
[in] | lat2 | Decimal Latitude (const double&) |
[in] | lon2 | Decimal Longitude (const double&) |
[in] | alpha | average bearing (double&) |
|
static |
Vincenty Inverse calculation giving WGS84 (decimal Lat/Long) position given a start location (lat,lon) a distance and a bearing See T. Vincenty, "Closed formulas for the direct and reverse geodetic problems", Journal of Geodesy, 51, 3, 1977, DOI:10.1007/BF02521599, see http://www.springerlink.com/content/y7108u6862473583 for more.
[in] | lat_ref | Decimal Latitude (const double&) |
[in] | lon_ref | Decimal Longitude (const double&) |
[in] | distance | Distance in meters (const double&) |
[in] | bearing | bearing in degrees, 0 being north (const double&) |
[out] | lat | Decimal latitude of target point (double&) |
[out] | lon | Decimal longitude of target point (double&) |
|
static |
Coordinate conversion: from WGS84 Lat/Long to Swiss grid See https://www.swisstopo.admin.ch/de/karten-daten-online/calculation-services.html in the "Documents" section for more.
[in] | lat_in | Decimal Latitude |
[in] | long_in | Decimal Longitude |
[out] | east_out | easting coordinate (Swiss system) |
[out] | north_out | northing coordinate (Swiss system) |
|
static |
Coordinate conversion: from WGS84 Lat/Long to proj parameters.
[in] | lat_in | Decimal Latitude |
[in] | long_in | Decimal Longitude |
[in] | coordparam | Extra parameters necessary for the conversion (such as UTM zone, etc) |
[out] | east_out | easting coordinate (target system) |
[out] | north_out | northing coordinate (target system) |
|
static |
Coordinate conversion: from WGS84 Lat/Long to Universal Polar Stereographic grid see J. Hager, J. Behensky, B. Drew, THE UNIVERSAL GRIDS: Universal Transverse Mercator (UTM) and Universal Polar Stereographic (UPS), 1989, Defense Mapping Agency, DMATM 8358.2. This is valid above latitudes 84N or above 80S.
[in] | lat_in | Decimal Latitude |
[in] | long_in | Decimal Longitude |
[in] | coordparam | UPS zone, either "N" or "S" |
[out] | east_out | easting coordinate (Swiss system) |
[out] | north_out | northing coordinate (Swiss system) |
|
static |
Coordinate conversion: from WGS84 Lat/Long to UTM grid. For more, see http://www.oc.nps.edu/oc2902w/maps/utmups.pdf, USGS Bulletin 1532 or http://earth-info.nga.mil/GandG/publications/tm8358.2/TM8358_2.pdf, http://www.uwgb.edu/dutchs/usefuldata/UTMFormulas.HTM or Chuck Gantz (http://www.gpsy.com/gpsinfo/geotoutm/).
[in] | lat_in | Decimal Latitude |
[in] | long_in | Decimal Longitude |
[in] | coordparam | UTM zone to convert to |
[out] | east_out | easting coordinate (Swiss system) |
[out] | north_out | northing coordinate (Swiss system) |