2727#define _s (const char *)
2828#define _qxml_getthestring (s ) qUtf8Printable((s).toString())
2929
30+ // Maps are usually in ESPG3857 format, not in GPS format EPSG4326 / WG84. We have to project
31+ // the latitude, otherwise big maps have wrong aspect ratio
32+ double project_latitude (double lat)
33+ {
34+ return log (tan (((90 + (double )lat) * MATH_PI ) / 360 )) / (MATH_PI / 180 );
35+ }
36+
37+ double unproject_latitude (double lat_projected)
38+ {
39+ return (atan (pow (exp (1 ), lat_projected * (MATH_PI / 180 )))*360 ) / MATH_PI - 90 ;
40+ }
41+
3042// shifts all (longitude) values from near 180 to 0
3143double get_180_swapped (double lon)
3244{
@@ -740,6 +752,7 @@ gps_point_proc weighted_middle_point_proc(gps_point_proc *p1,
740752 gps_point_proc crt_point = uninit_gps_proc_point;
741753 crt_point.lat
742754 = weighted_middle_double (p1->lat , p1->time , p2->lat , p2->time , new_t , max_gps_diff_ms);
755+ crt_point.lat_projected = project_latitude (crt_point.lat );
743756 crt_point.lon
744757 = weighted_middle_double (p1->lon , p1->time , p2->lon , p2->time , new_t , max_gps_diff_ms);
745758 crt_point.speed
@@ -960,6 +973,7 @@ void process_gps_smoothing(gps_private_data gdata, char do_processing)
960973 // these are not interpolated but as long as we're iterating we can copy them now
961974 gp_p[i].time = gp_r[i].time ;
962975 gp_p[i].lat = gp_r[i].lat ;
976+ gp_p[i].lat_projected = gp_r[i].lat_projected ;
963977 gp_p[i].lon = gp_r[i].lon ;
964978 }
965979 }
@@ -972,6 +986,7 @@ void process_gps_smoothing(gps_private_data gdata, char do_processing)
972986 if (req_smooth == 1 ) {
973987 // copy raw lat/lon to calc lat/lon and interpolate 1 location if necessary
974988 gps_points_p[i].lat = gps_points_r[i].lat ;
989+ gps_points_p[i].lat_projected = gps_points_r[i].lat_projected ;
975990 gps_points_p[i].lon = gps_points_r[i].lon ;
976991
977992 // this can happen often if location and altitude are stored at different time intervals (every 3s vs every 10s)
@@ -989,6 +1004,7 @@ void process_gps_smoothing(gps_private_data gdata, char do_processing)
9891004 gps_points_r[i + 1 ].time ,
9901005 gps_points_r[i].time ,
9911006 max_gps_diff_ms);
1007+ gps_points_p[i].lat_projected = project_latitude (gps_points_p[i].lat );
9921008 gps_points_p[i].lon = weighted_middle_double (gps_points_r[i - 1 ].lon ,
9931009 gps_points_r[i - 1 ].time ,
9941010 gps_points_r[i + 1 ].lon ,
@@ -1013,9 +1029,11 @@ void process_gps_smoothing(gps_private_data gdata, char do_processing)
10131029 }
10141030 if (nr_div != 0 ) {
10151031 gps_points_p[i].lat = lat_sum / nr_div;
1032+ gps_points_p[i].lat_projected = project_latitude (gps_points_p[i].lat );
10161033 gps_points_p[i].lon = lon_sum / nr_div;
10171034 } else {
10181035 gps_points_p[i].lat = gps_points_r[i].lat ;
1036+ gps_points_p[i].lat_projected = gps_points_r[i].lat ;
10191037 gps_points_p[i].lon = gps_points_r[i].lon ;
10201038 }
10211039 // mlt_log_info(filter, "i=%d, lat_sum=%f, lon_sum=%f, nr_div=%d, time=%d", i, lat_sum, lon_sum, nr_div, gps_points[i].time);
@@ -1060,7 +1078,10 @@ void qxml_parse_gpx(QXmlStreamReader &reader, gps_point_ll **gps_list, int *coun
10601078
10611079 QXmlStreamAttributes attributes = reader.attributes ();
10621080 if (attributes.hasAttribute (" lat" ))
1081+ {
10631082 crt_point.lat = attributes.value (" lat" ).toDouble ();
1083+ crt_point.lat_projected = project_latitude ( crt_point.lat );
1084+ }
10641085 if (attributes.hasAttribute (" lon" ))
10651086 crt_point.lon = attributes.value (" lon" ).toDouble ();
10661087
@@ -1215,8 +1236,10 @@ void qxml_parse_tcx(QXmlStreamReader &reader, gps_point_ll **gps_list, int *coun
12151236 qUtf8Printable (reader.readElementText ()));
12161237 else if (reader.name () == QStringLiteral (" Position" )) {
12171238 reader.readNextStartElement ();
1218- if (reader.name () == QStringLiteral (" LatitudeDegrees" ))
1239+ if (reader.name () == QStringLiteral (" LatitudeDegrees" )) {
12191240 crt_point.lat = reader.readElementText ().toDouble ();
1241+ crt_point.lat_projected = project_latitude (crt_point.lat );
1242+ }
12201243 reader.readNextStartElement ();
12211244 if (reader.name () == QStringLiteral (" LongitudeDegrees" ))
12221245 crt_point.lon = reader.readElementText ().toDouble ();
0 commit comments