Commit de9e42ba authored by Lefebvre, Jordan's avatar Lefebvre, Jordan
Browse files

Removing nested class declaration within CoordinateConversion.

parent c2b1b377
Pipeline #12909 failed with stages
in 6 minutes and 17 seconds
......@@ -6,36 +6,36 @@
namespace radix
{
const std::array<char, 22> CoordinateConversion::UTMZones::letters = {
const std::array<char, 22> UTMZones::letters = {
{'A', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M',
'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Z'}};
const std::array<short, 22> CoordinateConversion::UTMZones::degrees = {
const std::array<short, 22> UTMZones::degrees = {
{-90, -84, -72, -64, -56, -48, -40, -32, -24, -16, -8,
0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 84}};
const std::array<char, 11> CoordinateConversion::UTMZones::neg_letters = {
const std::array<char, 11> UTMZones::neg_letters = {
{'A', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M'}};
const std::array<short, 11> CoordinateConversion::UTMZones::neg_degrees = {
const std::array<short, 11> UTMZones::neg_degrees = {
{-90, -84, -72, -64, -56, -48, -40, -32, -24, -16, -8}};
const std::array<char, 11> CoordinateConversion::UTMZones::pos_letters = {
const std::array<char, 11> UTMZones::pos_letters = {
{'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Z'}};
const std::array<short, 11> CoordinateConversion::UTMZones::pos_degrees = {
const std::array<short, 11> UTMZones::pos_degrees = {
{0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 84}};
const std::array<char, 11>
CoordinateConversion::UTM2LatLon::southern_hemisphere = {
UTM2LatLon::southern_hemisphere = {
{'A', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'L', 'L', 'M'}};
short CoordinateConversion::UTMZones::latZoneDegree(char letter)
short UTMZones::latZoneDegree(char letter)
{
auto itr = std::find(letters.begin(), letters.end(), letter);
if (itr == letters.end()) return -100;
return *itr;
}
short CoordinateConversion::UTMZones::lonZone(double longitude)
short UTMZones::lonZone(double longitude)
{
double longZone = 0;
if (longitude < 0.0)
......@@ -49,7 +49,7 @@ short CoordinateConversion::UTMZones::lonZone(double longitude)
return short(longZone);
}
char CoordinateConversion::UTMZones::latZone(double latitude)
char UTMZones::latZone(double latitude)
{
short latIndex = -2;
short lat = short(latitude);
......@@ -121,7 +121,7 @@ char CoordinateConversion::UTMZones::latZone(double latitude)
}
}
double CoordinateConversion::LatLon2UTM::northing(double latitude) const
double LatLon2UTM::northing(double latitude) const
{
double northing = m_K1 + m_K2 * m_p * m_p + m_K3 * std::pow(m_p, 4.);
if (latitude < 0.0)
......@@ -131,12 +131,12 @@ double CoordinateConversion::LatLon2UTM::northing(double latitude) const
return northing;
}
double CoordinateConversion::LatLon2UTM::easting() const
double LatLon2UTM::easting() const
{
return 500000. + (m_K4 * m_p + m_K5 * std::pow(m_p, 3.));
}
CoordinateConversion::UTMCoordinate CoordinateConversion::LatLon2UTM::toUTM(
UTMCoordinate LatLon2UTM::toUTM(
double latitude, double longitude)
{
CoordinateConversion::validate(latitude, longitude);
......@@ -150,7 +150,7 @@ CoordinateConversion::UTMCoordinate CoordinateConversion::LatLon2UTM::toUTM(
return utm;
}
void CoordinateConversion::LatLon2UTM::init(double latitude, double longitude)
void LatLon2UTM::init(double latitude, double longitude)
{
latitude = radix::toRadians(latitude);
m_rho = m_equatorialRadius * (double(1.) - m_e * m_e) /
......@@ -226,8 +226,8 @@ void CoordinateConversion::validate(double latitude, double longitude)
}
}
void CoordinateConversion::UTM2LatLon::init(
const CoordinateConversion::UTMCoordinate& utm)
void UTM2LatLon::init(
const UTMCoordinate& utm)
{
m_arc = utm.northing / m_k0;
m_mu = m_arc /
......@@ -275,7 +275,7 @@ void CoordinateConversion::UTM2LatLon::init(
m_a3 = m_a2 * 180. / radix::PI;
}
char CoordinateConversion::UTM2LatLon::hemisphere(char latitude_zone)
char UTM2LatLon::hemisphere(char latitude_zone)
{
auto it = std::find(std::begin(southern_hemisphere),
std::end(southern_hemisphere), latitude_zone);
......@@ -289,8 +289,8 @@ char CoordinateConversion::UTM2LatLon::hemisphere(char latitude_zone)
}
}
std::pair<double, double> CoordinateConversion::UTM2LatLon::toLatLon(
const CoordinateConversion::UTMCoordinate& c)
std::pair<double, double> UTM2LatLon::toLatLon(
const UTMCoordinate& c)
{
UTMCoordinate utm = c;
double latitude = 0.;
......
......@@ -15,228 +15,227 @@ namespace radix
class RADIX_PUBLIC CoordinateConversion
{
public:
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
{
static const std::array<char, 22> letters;
static const std::array<short, 22> degrees;
/**
* @brief validate Validates coordinate
* @param latitude latitude coordinate
* @param longitude longitude coordinate
* Throws std::out_of_range exception if latitude is outside [-90.,90.] or
* longitude must be [-180,180).
*/
static void validate(double latitude, double longitude);
/**
* @brief validate Validates coordinate
* @param point where point.first is latitutde and point.second is longitude
* Throws std::out_of_range exception if latitude is outside [-90.,90.] or
* longitude must be [-180,180).
*/
static const std::array<char, 11> neg_letters;
static void validate(const std::pair<double, double>& point);
static const std::array<short, 11> neg_degrees;
}; // 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
{
static const std::array<char, 22> letters;
static const std::array<char, 11> pos_letters;
static const std::array<short, 22> degrees;
static const std::array<short, 11> pos_degrees;
static const std::array<char, 11> neg_letters;
public:
/**
* @brief latZoneDegree Latitude
* @param letter 'A' thru 'Z' zone
* @return short -90 thru 90 latitude zone offset
*/
static short latZoneDegree(char letter);
/**
* @brief lonZone Longitude zone
* @param longitude degrees
* @return short 0 thru 60 zone
*/
static short lonZone(double longitude);
static const std::array<short, 11> neg_degrees;
/**
* @brief latZone Latitude zone
* @param latitude degrees
* @return 'A' thru 'Z' zone
*/
static char latZone(double latitude);
}; // UTMZone
static const std::array<char, 11> pos_letters;
class RADIX_PUBLIC LatLon2UTM
{
private:
// equatorial radius
double m_equatorialRadius = double(6378137);
static const std::array<short, 11> pos_degrees;
// polar radius
double m_polarRadius = double(6356752.314);
public:
/**
* @brief latZoneDegree Latitude
* @param letter 'A' thru 'Z' zone
* @return short -90 thru 90 latitude zone offset
*/
static short latZoneDegree(char letter);
/**
* @brief lonZone Longitude zone
* @param longitude degrees
* @return short 0 thru 60 zone
*/
static short lonZone(double longitude);
// flattening
double m_flattening = double(
0.00335281066474748); // (equatorialRadius-polarRadius)/equatorialRadius;
/**
* @brief latZone Latitude zone
* @param latitude degrees
* @return 'A' thru 'Z' zone
*/
static char latZone(double latitude);
}; // UTMZone
// inverse flattening 1/flattening
double m_inverseFlattening = double(298.257223563); // 1/flattening;
class RADIX_PUBLIC LatLon2UTM
{
private:
// equatorial radius
double m_equatorialRadius = double(6378137);
// Mean radius
double m_rm =
std::pow(m_equatorialRadius * m_polarRadius, double(1.) / double(2.0));
// polar radius
double m_polarRadius = double(6356752.314);
// scale factor
double m_k0 = double(0.9996);
// flattening
double m_flattening = double(
0.00335281066474748); // (equatorialRadius-polarRadius)/equatorialRadius;
// eccentricity
double m_e = std::sqrt(
double(1) - std::pow(m_polarRadius / m_equatorialRadius, double(2.)));
// inverse flattening 1/flattening
double m_inverseFlattening = double(298.257223563); // 1/flattening;
double m_e1sq = m_e * m_e / (double(1) - m_e * m_e);
// Mean radius
double m_rm =
std::pow(m_equatorialRadius * m_polarRadius, double(1.) / double(2.0));
double m_n = (m_equatorialRadius - m_polarRadius) /
(m_equatorialRadius + m_polarRadius);
// scale factor
double m_k0 = double(0.9996);
// r curv 1
double m_rho = double(6368573.744);
// eccentricity
double m_e = std::sqrt(
double(1) - std::pow(m_polarRadius / m_equatorialRadius, double(2.)));
// r curv 2
double m_nu = double(6389236.914);
double m_e1sq = m_e * m_e / (double(1) - m_e * m_e);
// Calculate Meridional Arc Length
// Meridional Arc
double m_S = double(5103266.421);
double m_n = (m_equatorialRadius - m_polarRadius) /
(m_equatorialRadius + m_polarRadius);
double m_A0 = double(6367449.146);
// r curv 1
double m_rho = double(6368573.744);
double m_B0 = double(16038.42955);
// r curv 2
double m_nu = double(6389236.914);
double m_C0 = double(16.83261333);
// Calculate Meridional Arc Length
// Meridional Arc
double m_S = double(5103266.421);
double m_D0 = double(0.021984404);
double m_A0 = double(6367449.146);
double m_E0 = double(0.000312705);
double m_B0 = double(16038.42955);
// Calculation Constants
// Delta Long
double m_p = double(-0.483084);
double m_C0 = double(16.83261333);
double m_sin1 = double(4.84814E-06);
double m_D0 = double(0.021984404);
// Coefficients for UTM Coordinates
double m_K1 = double(5101225.115);
double m_E0 = double(0.000312705);
double m_K2 = double(3750.291596);
// Calculation Constants
// Delta Long
double m_p = double(-0.483084);
double m_K3 = double(1.397608151);
double m_sin1 = double(4.84814E-06);
double m_K4 = double(214839.3105);
// Coefficients for UTM Coordinates
double m_K1 = double(5101225.115);
double m_K5 = double(-2.995382942);
double m_K2 = double(3750.291596);
double m_A6 = double(-1.00541E-07);
double m_K3 = double(1.397608151);
/**
* @brief init initializes internal data necessary for coordinate conversion
* @param latitude degrees
* @param longitude degrees
*/
void init(double latitude, double longitude);
double m_K4 = double(214839.3105);
public:
double northing(double latitude) const;
double easting() const;
UTMCoordinate toUTM(double latitude, double longitude);
}; // class LatLon2UTM
double m_K5 = double(-2.995382942);
class RADIX_PUBLIC UTM2LatLon
{
private:
double m_arc;
double m_A6 = double(-1.00541E-07);
double m_mu;
/**
* @brief init initializes internal data necessary for coordinate conversion
* @param latitude degrees
* @param longitude degrees
*/
void init(double latitude, double longitude);
double m_ei;
public:
double northing(double latitude) const;
double easting() const;
UTMCoordinate toUTM(double latitude, double longitude);
}; // class LatLon2UTM
double m_ca;
class RADIX_PUBLIC UTM2LatLon
{
private:
double m_arc;
double m_cb;
double m_mu;
double m_cc;
double m_ei;
double m_cd;
double m_ca;
double m_n0;
double m_cb;
double m_r0;
double m_cc;
double m_a1;
double m_cd;
double m_dd0;
double m_n0;
double m_t0;
double m_r0;
double m_Q0;
double m_a1;
double m_lof1;
double m_dd0;
double m_lof2;
double m_t0;
double m_lof3;
double m_Q0;
double m_a2;
double m_lof1;
double m_phi1;
double m_lof2;
double m_fact1;
double m_lof3;
double m_fact2;
double m_a2;
double m_fact3;
double m_phi1;
double m_fact4;
double m_fact1;
double m_zoneCM;
double m_fact2;
double m_a3;
double m_fact3;
double m_b = 6356752.314;
double m_fact4;
double m_a = 6378137;
double m_zoneCM;
double m_e = 0.081819191;
double m_a3;
double m_e1sq = 0.006739497;
double m_b = 6356752.314;
double m_k0 = 0.9996;
double m_a = 6378137;
void init(const UTMCoordinate& utm);
double m_e = 0.081819191;
public:
static const std::array<char, 11> southern_hemisphere;
static char hemisphere(char latitude_zone);
std::pair<double, double> toLatLon(const UTMCoordinate& c);
}; // class UTM2LatLon
double m_e1sq = 0.006739497;
/**
* @brief validate Validates coordinate
* @param latitude latitude coordinate
* @param longitude longitude coordinate
* Throws std::out_of_range exception if latitude is outside [-90.,90.] or
* longitude must be [-180,180).
*/
static void validate(double latitude, double longitude);
/**
* @brief validate Validates coordinate
* @param point where point.first is latitutde and point.second is longitude
* Throws std::out_of_range exception if latitude is outside [-90.,90.] or
* longitude must be [-180,180).
*/
double m_k0 = 0.9996;
static void validate(const std::pair<double, double>& point);
void init(const UTMCoordinate& utm);
}; // class CoordinateConversion
public:
static const std::array<char, 11> southern_hemisphere;
static char hemisphere(char latitude_zone);
std::pair<double, double> toLatLon(const UTMCoordinate& c);
}; // class UTM2LatLon
} // namespace radix
#endif /** RADIX_RADIXGEO_COORDINATECONVERSION_HH_ */
......@@ -124,35 +124,35 @@ TEST(Radixgeo, CoordinateRange)
TEST(Radixgeo, UTMZones)
{
// latitude
EXPECT_EQ('N', CoordinateConversion::UTMZones::latZone(0.));
EXPECT_EQ('N', CoordinateConversion::UTMZones::latZone(0.13));
EXPECT_EQ('G', CoordinateConversion::UTMZones::latZone(-45.6456));
EXPECT_EQ('L', CoordinateConversion::UTMZones::latZone(-12.7650));
EXPECT_EQ('C', CoordinateConversion::UTMZones::latZone(-80.5434));
EXPECT_EQ('Z', CoordinateConversion::UTMZones::latZone(90.0000));
EXPECT_EQ('A', CoordinateConversion::UTMZones::latZone(-90.0000));
EXPECT_EQ('Q', CoordinateConversion::UTMZones::latZone(23.4578));
EXPECT_EQ('X', CoordinateConversion::UTMZones::latZone(77.3450));
EXPECT_EQ('A', CoordinateConversion::UTMZones::latZone(-89.3454));
EXPECT_EQ('N', UTMZones::latZone(0.));
EXPECT_EQ('N', UTMZones::latZone(0.13));
EXPECT_EQ('G', UTMZones::latZone(-45.6456));
EXPECT_EQ('L', UTMZones::latZone(-12.7650));
EXPECT_EQ('C', UTMZones::latZone(-80.5434));
EXPECT_EQ('Z', UTMZones::latZone(90.0000));
EXPECT_EQ('A', UTMZones::latZone(-90.0000));
EXPECT_EQ('Q', UTMZones::latZone(23.4578));
EXPECT_EQ('X', UTMZones::latZone(77.3450));
EXPECT_EQ('A', UTMZones::latZone(-89.3454));
// longitude
EXPECT_EQ(31, CoordinateConversion::UTMZones::lonZone(0.));
EXPECT_EQ(30, CoordinateConversion::UTMZones::lonZone(-0.2324));
EXPECT_EQ(34, CoordinateConversion::UTMZones::lonZone(23.3545));
EXPECT_EQ(25, CoordinateConversion::UTMZones::lonZone(-33.8765));
EXPECT_EQ(02, CoordinateConversion::UTMZones::lonZone(-170.6540));
EXPECT_EQ(60, CoordinateConversion::UTMZones::lonZone(177.0000));
EXPECT_EQ(01, CoordinateConversion::UTMZones::lonZone(-177.0000));
EXPECT_EQ(31, CoordinateConversion::UTMZones::lonZone(3.0000));
EXPECT_EQ(8, CoordinateConversion::UTMZones::lonZone(-135.4545));
EXPECT_EQ(57, CoordinateConversion::UTMZones::lonZone(156.9876));
EXPECT_EQ(22, CoordinateConversion::UTMZones::lonZone(-48.9306));
EXPECT_EQ(31, UTMZones::lonZone(0.));
EXPECT_EQ(30, UTMZones::lonZone(-0.2324));
EXPECT_EQ(34, UTMZones::lonZone(23.3545));
EXPECT_EQ(25, UTMZones::lonZone(-33.8765));
EXPECT_EQ(02, UTMZones::lonZone(-170.6540));
EXPECT_EQ(60, UTMZones::lonZone(177.0000));
EXPECT_EQ(01, UTMZones::lonZone(-177.0000));
EXPECT_EQ(31, UTMZones::lonZone(3.0000));
EXPECT_EQ(8, UTMZones::lonZone(-135.4545));
EXPECT_EQ(57, UTMZones::lonZone(156.9876));
EXPECT_EQ(22, UTMZones::lonZone(-48.9306));
}
TEST(Radixgeo, LatLon2UTM)
{
double fuzzy = 1;
CoordinateConversion::LatLon2UTM conv;
CoordinateConversion::UTMCoordinate utm = conv.toUTM(0.0000, 0.0000);
LatLon2UTM conv;
UTMCoordinate utm = conv.toUTM(0.0000, 0.0000);
EXPECT_EQ(31, utm.longitude_zone);
EXPECT_EQ('N', utm.lattitude_zone);
EXPECT_NEAR(166021.329, utm.easting, fuzzy);
......@@ -228,14 +228,14 @@ TEST(Radixgeo, LatLon2UTM)
TEST(Radixgeo, UTM2LatLon)
{
double fuzzy = 1e-2;
EXPECT_EQ('S', CoordinateConversion::UTM2LatLon::hemisphere('A'));
EXPECT_EQ('S', CoordinateConversion::UTM2LatLon::hemisphere('M'));
EXPECT_EQ('N', CoordinateConversion::UTM2LatLon::hemisphere('N'));
EXPECT_EQ('N', CoordinateConversion::UTM2LatLon::hemisphere('Z'));
CoordinateConversion::LatLon2UTM latLonConv;
CoordinateConversion::UTM2LatLon utmConv;
CoordinateConversion::UTMCoordinate utm = latLonConv.toUTM(0.0000, 0.0000);
EXPECT_EQ('S', UTM2LatLon::hemisphere('A'));
EXPECT_EQ('S', UTM2LatLon::hemisphere('M'));
EXPECT_EQ('N', UTM2LatLon::hemisphere('N'));
EXPECT_EQ('N', UTM2LatLon::hemisphere('Z'));
LatLon2UTM latLonConv;
UTM2LatLon utmConv;
UTMCoordinate utm = latLonConv.toUTM(0.0000, 0.0000);
std::pair<double, double> latLong = utmConv.toLatLon(utm);
EXPECT_NEAR(0., latLong.first, fuzzy);
EXPECT_NEAR(0., latLong.second, fuzzy);
......
Markdown is supported
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