7 #include <QNetworkAccessManager>
9 #include <QNetworkRequest>
10 #include <QNetworkReply>
11 #include <QXmlStreamReader>
13 #include <QXmlStreamAttributes>
15 #include <QGeoPositionInfo>
19 const double KkjZoneInfo[6][2] = {
30 Location::Location( const QString &x, const QString &y, const QString &label ) :
39 Location::Location(const QGeoPositionInfo &positionInfo, const QString &label) :
46 setLocation(positionInfo);
49 void Location::setLocation(const QGeoPositionInfo &positionInfo)
51 qDebug() << "Setting new location based on GeoPositionInfo";
52 qreal latitude = positionInfo.coordinate().latitude();
53 qreal longitude = positionInfo.coordinate().longitude();
55 //qDebug() << "Calculating new values";
60 WGS84lola_to_KKJxy( longitude, latitude, &outX, &outY);
62 /*qDebug() << "Storing new values";
68 //qDebug() << "Setting x";
69 //this->m_x = QString("%1").arg(outX);
70 this->m_x.setNum(outX);
71 //qDebug() << "Setting y";
72 //this->m_y = QString("%1").arg(outY);
73 this->m_y.setNum(outY);
74 //qDebug() << "Setting as valid";
77 //qDebug() << "Location set";
80 void Location::setPosition(const QString &x, const QString &y)
87 Location::Location(const QString &label) :
96 Location::Location(const Location *location) :
97 m_label(location->m_label),
98 m_address(location->m_address),
101 m_valid(location->m_valid)
105 QString Location::x() const
110 QString Location::y() const
115 void Location::setLabel(const QString &label)
120 QString Location::label() const
125 void Location::setAddress(const QString &address)
130 QString Location::address() const
135 bool Location::isValid() const
140 // Degrees to radians
141 double radians(double deg)
143 return deg * M_PI / 180.0;
146 // Radians to degrees
147 double degrees(double rad)
149 return rad * 180.0 / M_PI;
152 // Function: KKJ_Zone_I
153 int KKJ_Zone_I(KKJ easting)
155 int zoneNumber = floor(easting / 1000000.0);
156 if (zoneNumber < 0 || zoneNumber > 5) {
163 // Function: KKJ_Zone_Lo
164 int KKJ_Zone_Lo(double kkjlo)
166 // determine the zonenumber from KKJ easting
167 // takes KKJ zone which has center meridian
168 // longitude nearest (in math value) to
169 // the given KKJ longitude
171 while (zoneNumber >= 0) {
172 if (fabs(kkjlo - KkjZoneInfo[zoneNumber][0]) <= 1.5) {
182 // Function: KKJlalo_to_WGS84lalo
183 void KKJlola_to_WGS84lola(double kkjlo, double kkjla, double *outLongitude, double *outLatitude)
185 double dLa = radians(0.124867E+01 + -0.269982E+00 * kkjla + 0.191330E+00 * kkjlo + 0.356119E-02 * kkjla * kkjla + -0.122312E-02 * kkjla * kkjlo + -0.335514E-03 * kkjlo * kkjlo) / 3600.0;
186 double dLo = radians(-0.286111E+02 + 0.114183E+01 * kkjla + -0.581428E+00 * kkjlo + -0.152421E-01 * kkjla * kkjla + 0.118177E-01 * kkjla * kkjlo + 0.826646E-03 * kkjlo * kkjlo) / 3600.0;
188 *outLatitude = degrees(radians(kkjla) + dLa);
189 *outLongitude = degrees(radians(kkjlo) + dLo);
193 // Function: WGS84lalo_to_KKJlalo
194 void WGS84lola_to_KKJlola(double longitude, double latitude, double *outLongitude, double *outLatitude)
196 double dLa = radians(-0.124766E+01 + 0.269941E+00 * latitude + -0.191342E+00 * longitude + -0.356086E-02 * latitude * latitude + 0.122353E-02 * latitude * longitude + 0.335456E-03 * longitude * longitude) / 3600.0;
197 double dLo = radians(0.286008E+02 + -0.114139E+01 * latitude + 0.581329E+00 * longitude + 0.152376E-01 * latitude * latitude + -0.118166E-01 * latitude * longitude + -0.826201E-03 * longitude * longitude) / 3600.0;
199 *outLatitude = degrees(radians(latitude) + dLa);
200 *outLongitude = degrees(radians(longitude) + dLo);
204 // Function: KKJlalo_to_KKJxy
205 void KKJlola_to_KKJxy(double lon, double lat, int zoneNumber, KKJ *outX, KKJ *outY)
208 double a = 6378388.0;
209 double f = 1.0 / 297.0;
210 double b = (1.0 - f) * a;
212 double c = (a / b) * a;
213 double ee = (a * a - bb) / bb;
214 double n = (a - b) / (a + b);
217 double Lo = radians(lon) - radians(KkjZoneInfo[zoneNumber][0]);
218 double cosLa = cos(radians(lat));
219 double NN = ee * cosLa * cosLa;
220 double LaF = atan(tan(radians(lat)) / cos(Lo * sqrt(1.0 + NN)));
221 double cosLaF = cos(LaF);
222 double t = (tan(Lo) * cosLaF) / sqrt(1.0 + ee * cosLaF * cosLaF);
223 double A = a / (1.0 + n);
224 double A1 = A * (1.0 + nn / 4.0 + nn * nn / 64.0);
225 double A2 = A * 1.5 * n * (1.0 - nn / 8.0);
226 double A3 = A * 0.9375 * nn * (1.0 - nn / 4.0);
227 double A4 = A * 35.0 / 48.0 * nn * n;
229 *outY = A1 * LaF - A2 * sin(2.0 * LaF) + A3 * sin(4.0 * LaF) - A4 * sin(6.0 * LaF);
230 *outX = c * log(t + sqrt(1.0 + t * t)) + 500000.0 + zoneNumber * 1000000.0;
233 // Function: KKJxy_to_KKJlalo
234 void KKJxy_to_KKJlola(KKJ x, KKJ y, double *outLongitude, double *outLatitude)
236 // Scan iteratively the target area, until find matching
237 // KKJ coordinate value. Area is defined with Hayford Ellipsoid.
238 int zoneNumber = KKJ_Zone_I(x);
239 double minLo = radians(18.5);
240 double maxLo = radians(32.0);
241 double minLa = radians(59.0);
242 double maxLa = radians(70.5);
248 double deltaLo = maxLo - minLo;
249 double deltaLa = maxLa - minLa;
250 *outLongitude = degrees(minLo + 0.5 * deltaLo);
251 *outLatitude = degrees(minLa + 0.5 * deltaLa);
252 KKJlola_to_KKJxy(*outLongitude, *outLatitude, zoneNumber, &tmpX, &tmpY);
254 minLa = minLa + 0.45 * deltaLa;
256 maxLa = minLa + 0.55 * deltaLa;
260 minLo = minLo + 0.45 * deltaLo;
262 maxLo = minLo + 0.55 * deltaLo;
269 void WGS84lola_to_KKJxy(double longitude, double latitude, KKJ *outX, KKJ *outY)
273 WGS84lola_to_KKJlola(longitude, latitude, &kkjlo, &kkjla);
274 int zoneNumber = KKJ_Zone_Lo(kkjlo);
275 KKJlola_to_KKJxy(kkjlo, kkjla, zoneNumber, outX, outY);
278 void KKJxy_to_WGS84lola(KKJ x, KKJ y, double *outLongitude, double *outLatitude)
282 KKJxy_to_KKJlola(x, y, &kkjlo, &kkjla);
283 KKJlola_to_WGS84lola(kkjlo, kkjla, outLongitude, outLatitude);