1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-23 16:25:16 +03:00

Export to Google Earth now working (only) with the new telemetry fields (GPS, GAlt and GSpd)

This commit is contained in:
Damjan Adamic 2015-08-01 10:53:06 +02:00
parent 922220c748
commit 70d67dd7dd
3 changed files with 36 additions and 23 deletions

View file

@ -1112,3 +1112,18 @@ double toDecimalCoordinate(const QString & value)
} }
return result; return result;
} }
QStringList extractLatLon(const QString & position)
{
QStringList result;
QStringList parts = position.split(' ');
if (parts.size() != 2) {
result.append("");
result.append("");
}
else {
result.append(parts.at(1).trimmed());
result.append(parts.at(0).trimmed());
}
return result;
}

View file

@ -207,5 +207,6 @@ private:
}; };
double toDecimalCoordinate(const QString & value); double toDecimalCoordinate(const QString & value);
QStringList extractLatLon(const QString & position);
#endif // HELPERS_H #endif // HELPERS_H

View file

@ -217,17 +217,16 @@ QList<QStringList> LogsDialog::filterGePoints(const QList<QStringList> & input)
return result; return result;
} }
int latcol=0, longcol=0; int gpscol = 0;
for (int i=1; i<input.at(0).count(); i++) { for (int i=1; i<input.at(0).count(); i++) {
//Long,Lat,Course,GPS Speed,GPS Alt if (input.at(0).at(i) == "GPS") {
if (input.at(0).at(i).contains("Long")) { gpscol=i;
longcol=i;
}
if (input.at(0).at(i).contains("Lat")) {
latcol=i;
} }
} }
if (longcol==0 || latcol==0) { if (gpscol == 0) {
QMessageBox::critical(this, tr("Error: no GPS data not found"),
tr("The column containing GPS coordinates must be named \"GPS\".\n\n\
The columns for altitude \"GAlt\" and for speed \"GSpd\" are optional"));
return result; return result;
} }
@ -240,8 +239,9 @@ QList<QStringList> LogsDialog::filterGePoints(const QList<QStringList> & input)
for (int i = 1; i < n; i++) { for (int i = 1; i < n; i++) {
if ((ui->logTable->item(i-1, 1)->isSelected() && rangeSelected) || !rangeSelected) { if ((ui->logTable->item(i-1, 1)->isSelected() && rangeSelected) || !rangeSelected) {
QString latitude = input.at(i).at(latcol).trimmed(); QStringList latlon = extractLatLon(input.at(i).at(gpscol));
QString longitude = input.at(i).at(longcol).trimmed(); QString latitude = latlon[0];
QString longitude = latlon[1];
double flatitude = toDecimalCoordinate(latitude); double flatitude = toDecimalCoordinate(latitude);
double flongitude = toDecimalCoordinate(longitude); double flongitude = toDecimalCoordinate(longitude);
@ -273,32 +273,28 @@ void LogsDialog::exportToGoogleEarth()
int n = dataPoints.count(); // number of points to export int n = dataPoints.count(); // number of points to export
if (n==0) return; if (n==0) return;
int latcol=0, longcol=0, altcol=0, speedcol=0; int gpscol=0, altcol=0, speedcol=0;
QSet<int> nondataCols; QSet<int> nondataCols;
for (int i=1; i<dataPoints.at(0).count(); i++) { for (int i=1; i<dataPoints.at(0).count(); i++) {
// Long,Lat,Course,GPS Speed,GPS Alt // Long,Lat,Course,GPS Speed,GPS Alt
if (dataPoints.at(0).at(i).contains("Long")) { if (dataPoints.at(0).at(i) == "GPS") {
longcol = i; gpscol=i;
nondataCols << i;
} }
if (dataPoints.at(0).at(i).contains("Lat")) { if (dataPoints.at(0).at(i).contains("GAlt")) {
latcol = i;
nondataCols << i;
}
if (dataPoints.at(0).at(i).contains("GPS Alt") || dataPoints.at(0).at(i).contains("GAlt")) {
altcol = i; altcol = i;
nondataCols << i; nondataCols << i;
} }
if (dataPoints.at(0).at(i).contains("GPS Speed")) { if (dataPoints.at(0).at(i).contains("GSpd")) {
speedcol = i; speedcol = i;
nondataCols << i; nondataCols << i;
} }
} }
if (longcol==0 || latcol==0) { if (gpscol==0 ) {
return; return;
} }
// qDebug() << "gpscol" << gpscol << "altcol" << altcol << "speedcol" << speedcol;
QString geIconFilename = generateProcessUniqueTempFileName("track0.png"); QString geIconFilename = generateProcessUniqueTempFileName("track0.png");
if (QFile::exists(geIconFilename)) { if (QFile::exists(geIconFilename)) {
QFile::remove(geIconFilename); QFile::remove(geIconFilename);
@ -363,8 +359,9 @@ void LogsDialog::exportToGoogleEarth()
// coordinate data points // coordinate data points
for (int i=1; i<n; i++) { for (int i=1; i<n; i++) {
QString latitude = dataPoints.at(i).at(latcol).trimmed(); QStringList latlon = extractLatLon(dataPoints.at(i).at(gpscol));
QString longitude = dataPoints.at(i).at(longcol).trimmed(); QString latitude = latlon[0];
QString longitude = latlon[1];
int altitude = altcol ? dataPoints.at(i).at(altcol).toFloat() : 0; int altitude = altcol ? dataPoints.at(i).at(altcol).toFloat() : 0;
latitude.sprintf("%3.8f", toDecimalCoordinate(latitude)); latitude.sprintf("%3.8f", toDecimalCoordinate(latitude));
longitude.sprintf("%3.8f", toDecimalCoordinate(longitude)); longitude.sprintf("%3.8f", toDecimalCoordinate(longitude));