Commit 7a855d8f authored by LEFEBVREJP email's avatar LEFEBVREJP email
Browse files

Adding toString helper for UTMCoordinate.

parent de9e42ba
Pipeline #12911 failed with stages
in 6 minutes and 15 seconds
...@@ -25,9 +25,8 @@ const std::array<char, 11> UTMZones::pos_letters = { ...@@ -25,9 +25,8 @@ const std::array<char, 11> UTMZones::pos_letters = {
const std::array<short, 11> UTMZones::pos_degrees = { const std::array<short, 11> UTMZones::pos_degrees = {
{0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 84}}; {0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 84}};
const std::array<char, 11> const std::array<char, 11> UTM2LatLon::southern_hemisphere = {
UTM2LatLon::southern_hemisphere = { {'A', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'L', 'L', 'M'}};
{'A', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'L', 'L', 'M'}};
short UTMZones::latZoneDegree(char letter) short UTMZones::latZoneDegree(char letter)
{ {
auto itr = std::find(letters.begin(), letters.end(), letter); auto itr = std::find(letters.begin(), letters.end(), letter);
...@@ -136,8 +135,7 @@ double LatLon2UTM::easting() const ...@@ -136,8 +135,7 @@ double LatLon2UTM::easting() const
return 500000. + (m_K4 * m_p + m_K5 * std::pow(m_p, 3.)); return 500000. + (m_K4 * m_p + m_K5 * std::pow(m_p, 3.));
} }
UTMCoordinate LatLon2UTM::toUTM( UTMCoordinate LatLon2UTM::toUTM(double latitude, double longitude)
double latitude, double longitude)
{ {
CoordinateConversion::validate(latitude, longitude); CoordinateConversion::validate(latitude, longitude);
UTMCoordinate utm; UTMCoordinate utm;
...@@ -212,6 +210,14 @@ void CoordinateConversion::validate(const std::pair<double, double>& point) ...@@ -212,6 +210,14 @@ void CoordinateConversion::validate(const std::pair<double, double>& point)
CoordinateConversion::validate(point.first, point.second); CoordinateConversion::validate(point.first, point.second);
} }
std::string CoordinateConversion::toString(const UTMCoordinate& utm)
{
char buff[120];
sprintf(buff, "%02d %c %f %f", utm.longitude_zone, utm.lattitude_zone,
utm.easting, utm.northing);
return std::string(buff);
}
void CoordinateConversion::validate(double latitude, double longitude) void CoordinateConversion::validate(double latitude, double longitude)
{ {
radix_tagged_line("Validating (" << latitude << "," << longitude << ")"); radix_tagged_line("Validating (" << latitude << "," << longitude << ")");
...@@ -226,8 +232,7 @@ void CoordinateConversion::validate(double latitude, double longitude) ...@@ -226,8 +232,7 @@ void CoordinateConversion::validate(double latitude, double longitude)
} }
} }
void UTM2LatLon::init( void UTM2LatLon::init(const UTMCoordinate& utm)
const UTMCoordinate& utm)
{ {
m_arc = utm.northing / m_k0; m_arc = utm.northing / m_k0;
m_mu = m_arc / m_mu = m_arc /
...@@ -289,8 +294,7 @@ char UTM2LatLon::hemisphere(char latitude_zone) ...@@ -289,8 +294,7 @@ char UTM2LatLon::hemisphere(char latitude_zone)
} }
} }
std::pair<double, double> UTM2LatLon::toLatLon( std::pair<double, double> UTM2LatLon::toLatLon(const UTMCoordinate& c)
const UTMCoordinate& c)
{ {
UTMCoordinate utm = c; UTMCoordinate utm = c;
double latitude = 0.; double latitude = 0.;
......
...@@ -12,6 +12,20 @@ ...@@ -12,6 +12,20 @@
namespace radix namespace radix
{ {
struct RADIX_PUBLIC UTMCoordinate
{
// earth radius is ~40million meteres
// int will cover this
double easting;
double northing;
// 00 -> 60 longitude zones
short longitude_zone;
// Not officially part of UTM
// but frequently used with UTM
// C - > X, (A,B,Y,Z) are not used as they cover western and eastern sides
// of the Antarctic and Arctic regions
char lattitude_zone;
};
class RADIX_PUBLIC CoordinateConversion class RADIX_PUBLIC CoordinateConversion
{ {
public: public:
...@@ -32,21 +46,14 @@ class RADIX_PUBLIC CoordinateConversion ...@@ -32,21 +46,14 @@ class RADIX_PUBLIC CoordinateConversion
static void validate(const std::pair<double, double>& point); static void validate(const std::pair<double, double>& point);
/**
* @brief toString Converts UTM coordinate to string representation
* @param utm
* @return std::string "11 S 400000 5500"
*/
static std::string toString(const UTMCoordinate& utm);
}; // class CoordinateConversion }; // class CoordinateConversion
struct RADIX_PUBLIC UTMCoordinate
{
// earth radius is ~40million meteres
// int will cover this
double easting;
double northing;
// 00 -> 60 longitude zones
short longitude_zone;
// Not officially part of UTM
// but frequently used with UTM
// C - > X, (A,B,Y,Z) are not used as they cover western and eastern sides
// of the Antarctic and Arctic regions
char lattitude_zone;
};
class RADIX_PUBLIC UTMZones class RADIX_PUBLIC UTMZones
{ {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment