mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-01-19 04:02:09 +01:00
Added correct handling of the DMS degree definition (9110)
This commit is contained in:
parent
652ed8e919
commit
d6de3acbd2
@ -1,7 +1,52 @@
|
||||
#include "common/coordinates.h"
|
||||
#include "data/str2int.h"
|
||||
#include "angularunits.h"
|
||||
|
||||
AngularUnits::AngularUnits(int code)
|
||||
static double sDMS2deg(double val)
|
||||
{
|
||||
double angle;
|
||||
char *decimal;
|
||||
char str[13];
|
||||
|
||||
if (val < -999.9 || val > 999.9)
|
||||
return NAN;
|
||||
|
||||
sprintf(str, "%.7f", qAbs(val));
|
||||
decimal = strchr(str,'.');
|
||||
int deg = str2int(str, decimal - str);
|
||||
int min = str2int(decimal + 1, 2);
|
||||
int sec = str2int(decimal + 3, 2);
|
||||
int f = str2int(decimal + 5, 3);
|
||||
|
||||
angle = deg + (double)min/60.0 + (double)sec/3600.0
|
||||
+ ((double)f/1000.0)/3600.0;
|
||||
|
||||
return (val < 0) ? -angle : angle;
|
||||
}
|
||||
|
||||
static double deg2sDMS(double val)
|
||||
{
|
||||
char str[13];
|
||||
double aval = qAbs(val);
|
||||
|
||||
if (val < -999.9 || val > 999.9)
|
||||
return NAN;
|
||||
|
||||
int deg = aval;
|
||||
double r1 = aval - deg;
|
||||
|
||||
int min = r1 * 60.0;
|
||||
double r2 = r1 - (min / 60.0);
|
||||
|
||||
int sec = r2 * 3600.0;
|
||||
double r3 = r2 - (sec / 3600.0);
|
||||
int f = (int)(r3 * 3600.0 * 1000.0);
|
||||
|
||||
sprintf(str, "%u.%02u%02u%03u", deg, min, sec, f);
|
||||
return (val < 0) ? -atof(str) : atof(str);
|
||||
}
|
||||
|
||||
AngularUnits::AngularUnits(int code) : _code(code)
|
||||
{
|
||||
switch (code) {
|
||||
case 9101:
|
||||
@ -34,6 +79,16 @@ AngularUnits::AngularUnits(int code)
|
||||
}
|
||||
}
|
||||
|
||||
double AngularUnits::toDegrees(double val) const
|
||||
{
|
||||
return (_code == 9110) ? sDMS2deg(val) : val * _f;
|
||||
}
|
||||
|
||||
double AngularUnits::fromDegrees(double val) const
|
||||
{
|
||||
return (_code == 9110) ? deg2sDMS(val) : val / _f;
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug dbg, const AngularUnits &au)
|
||||
{
|
||||
dbg.nospace() << "AngularUnits(" << deg2rad(au._f) << ")";
|
||||
|
@ -7,19 +7,20 @@
|
||||
class AngularUnits
|
||||
{
|
||||
public:
|
||||
AngularUnits() : _f(NAN) {}
|
||||
AngularUnits() : _code(0), _f(NAN) {}
|
||||
AngularUnits(int code);
|
||||
|
||||
bool isNull() const {return std::isnan(_f);}
|
||||
bool isValid() const {return !std::isnan(_f);}
|
||||
|
||||
double toDegrees(double val) const {return val * _f;}
|
||||
double fromDegrees(double val) const {return val / _f;}
|
||||
double toDegrees(double val) const;
|
||||
double fromDegrees(double val) const;
|
||||
|
||||
friend bool operator==(const AngularUnits &au1, const AngularUnits &au2);
|
||||
friend QDebug operator<<(QDebug dbg, const AngularUnits &au);
|
||||
|
||||
private:
|
||||
int _code;
|
||||
double _f;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user