forked from upstream-mirrors/OpenTracks
UI presents altitude in EGM2008.
This commit is contained in:
@@ -75,7 +75,7 @@ public class EGM2008UtilsTest {
|
|||||||
trackPoint.setAltitude(0);
|
trackPoint.setAltitude(0);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
EGM2008Utils.EGM2008Correction altitude_egm2008 = EGM2008Utils.createEGM2008Correction(context, trackPoint.getLocation());
|
EGM2008Utils.EGM2008Correction altitude_egm2008 = EGM2008Utils.createCorrection(context, trackPoint.getLocation());
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertEquals(-14.8980, altitude_egm2008.correctAltitude(trackPoint.getLocation()), MAX_BILINEAR_ERROR);
|
assertEquals(-14.8980, altitude_egm2008.correctAltitude(trackPoint.getLocation()), MAX_BILINEAR_ERROR);
|
||||||
@@ -90,7 +90,7 @@ public class EGM2008UtilsTest {
|
|||||||
trackPoint.setAltitude(0);
|
trackPoint.setAltitude(0);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
EGM2008Utils.EGM2008Correction altitude_egm2008 = EGM2008Utils.createEGM2008Correction(context, trackPoint.getLocation());
|
EGM2008Utils.EGM2008Correction altitude_egm2008 = EGM2008Utils.createCorrection(context, trackPoint.getLocation());
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertEquals(30.15, altitude_egm2008.correctAltitude(trackPoint.getLocation()), MAX_BILINEAR_ERROR);
|
assertEquals(30.15, altitude_egm2008.correctAltitude(trackPoint.getLocation()), MAX_BILINEAR_ERROR);
|
||||||
@@ -105,7 +105,7 @@ public class EGM2008UtilsTest {
|
|||||||
trackPoint.setAltitude(0);
|
trackPoint.setAltitude(0);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
EGM2008Utils.EGM2008Correction altitude_egm2008 = EGM2008Utils.createEGM2008Correction(context, trackPoint.getLocation());
|
EGM2008Utils.EGM2008Correction altitude_egm2008 = EGM2008Utils.createCorrection(context, trackPoint.getLocation());
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertEquals(30.15, altitude_egm2008.correctAltitude(trackPoint.getLocation()), MAX_BILINEAR_ERROR);
|
assertEquals(30.15, altitude_egm2008.correctAltitude(trackPoint.getLocation()), MAX_BILINEAR_ERROR);
|
||||||
@@ -120,7 +120,7 @@ public class EGM2008UtilsTest {
|
|||||||
trackPoint.setAltitude(0);
|
trackPoint.setAltitude(0);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
EGM2008Utils.EGM2008Correction altitude_egm2008 = EGM2008Utils.createEGM2008Correction(context, trackPoint.getLocation());
|
EGM2008Utils.EGM2008Correction altitude_egm2008 = EGM2008Utils.createCorrection(context, trackPoint.getLocation());
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertEquals(30.15, altitude_egm2008.correctAltitude(trackPoint.getLocation()), MAX_BILINEAR_ERROR);
|
assertEquals(30.15, altitude_egm2008.correctAltitude(trackPoint.getLocation()), MAX_BILINEAR_ERROR);
|
||||||
@@ -135,7 +135,7 @@ public class EGM2008UtilsTest {
|
|||||||
trackPoint.setAltitude(0);
|
trackPoint.setAltitude(0);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
EGM2008Utils.EGM2008Correction altitude_egm2008 = EGM2008Utils.createEGM2008Correction(context, trackPoint.getLocation());
|
EGM2008Utils.EGM2008Correction altitude_egm2008 = EGM2008Utils.createCorrection(context, trackPoint.getLocation());
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertEquals(-17.2260, altitude_egm2008.correctAltitude(trackPoint.getLocation()), MAX_BILINEAR_ERROR);
|
assertEquals(-17.2260, altitude_egm2008.correctAltitude(trackPoint.getLocation()), MAX_BILINEAR_ERROR);
|
||||||
@@ -150,7 +150,7 @@ public class EGM2008UtilsTest {
|
|||||||
trackPoint.setAltitude(0);
|
trackPoint.setAltitude(0);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
EGM2008Utils.EGM2008Correction altitude_egm2008 = EGM2008Utils.createEGM2008Correction(context, trackPoint.getLocation());
|
EGM2008Utils.EGM2008Correction altitude_egm2008 = EGM2008Utils.createCorrection(context, trackPoint.getLocation());
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertEquals(-39.4865, altitude_egm2008.correctAltitude(trackPoint.getLocation()), MAX_BILINEAR_ERROR);
|
assertEquals(-39.4865, altitude_egm2008.correctAltitude(trackPoint.getLocation()), MAX_BILINEAR_ERROR);
|
||||||
@@ -170,7 +170,7 @@ public class EGM2008UtilsTest {
|
|||||||
trackPoint2.setAltitude(0);
|
trackPoint2.setAltitude(0);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
EGM2008Utils.EGM2008Correction altitude_egm2008 = EGM2008Utils.createEGM2008Correction(context, trackPoint1.getLocation());
|
EGM2008Utils.EGM2008Correction altitude_egm2008 = EGM2008Utils.createCorrection(context, trackPoint1.getLocation());
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertNotEquals(altitude_egm2008.correctAltitude(trackPoint1.getLocation()), altitude_egm2008.correctAltitude(trackPoint2.getLocation()), 0.0001);
|
assertNotEquals(altitude_egm2008.correctAltitude(trackPoint1.getLocation()), altitude_egm2008.correctAltitude(trackPoint2.getLocation()), 0.0001);
|
||||||
@@ -185,7 +185,7 @@ public class EGM2008UtilsTest {
|
|||||||
trackPoint.setAltitude(0);
|
trackPoint.setAltitude(0);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
EGM2008Utils.EGM2008Correction altitude_egm2008 = EGM2008Utils.createEGM2008Correction(context, trackPoint.getLocation());
|
EGM2008Utils.EGM2008Correction altitude_egm2008 = EGM2008Utils.createCorrection(context, trackPoint.getLocation());
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertEquals(-85.824, altitude_egm2008.correctAltitude(trackPoint.getLocation()), MAX_BILINEAR_ERROR);
|
assertEquals(-85.824, altitude_egm2008.correctAltitude(trackPoint.getLocation()), MAX_BILINEAR_ERROR);
|
||||||
|
|||||||
@@ -27,9 +27,11 @@ import android.util.Log;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import de.dennisguse.opentracks.content.data.Altitude;
|
||||||
import de.dennisguse.opentracks.content.data.Distance;
|
import de.dennisguse.opentracks.content.data.Distance;
|
||||||
import de.dennisguse.opentracks.content.data.Marker;
|
import de.dennisguse.opentracks.content.data.Marker;
|
||||||
import de.dennisguse.opentracks.content.data.MarkerColumns;
|
import de.dennisguse.opentracks.content.data.MarkerColumns;
|
||||||
@@ -41,6 +43,7 @@ import de.dennisguse.opentracks.content.provider.ContentProviderUtils;
|
|||||||
import de.dennisguse.opentracks.content.provider.TrackPointIterator;
|
import de.dennisguse.opentracks.content.provider.TrackPointIterator;
|
||||||
import de.dennisguse.opentracks.services.TrackRecordingService;
|
import de.dennisguse.opentracks.services.TrackRecordingService;
|
||||||
import de.dennisguse.opentracks.stats.TrackStatisticsUpdater;
|
import de.dennisguse.opentracks.stats.TrackStatisticsUpdater;
|
||||||
|
import de.dennisguse.opentracks.util.EGM2008Utils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Track data hub.
|
* Track data hub.
|
||||||
@@ -72,6 +75,8 @@ public class TrackDataHub {
|
|||||||
private final ContentProviderUtils contentProviderUtils;
|
private final ContentProviderUtils contentProviderUtils;
|
||||||
private final int targetNumPoints;
|
private final int targetNumPoints;
|
||||||
|
|
||||||
|
private EGM2008Utils.EGM2008Correction egm2008Correction;
|
||||||
|
|
||||||
private boolean started;
|
private boolean started;
|
||||||
private HandlerThread handlerThread;
|
private HandlerThread handlerThread;
|
||||||
private Handler handler;
|
private Handler handler;
|
||||||
@@ -364,6 +369,8 @@ public class TrackDataHub {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
correctAltitude(trackPoint);
|
||||||
|
|
||||||
if (localFirstSeenTrackPointId == null) {
|
if (localFirstSeenTrackPointId == null) {
|
||||||
localFirstSeenTrackPointId = trackPointId;
|
localFirstSeenTrackPointId = trackPointId;
|
||||||
}
|
}
|
||||||
@@ -407,6 +414,24 @@ public class TrackDataHub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void correctAltitude(TrackPoint trackPoint) {
|
||||||
|
if (!trackPoint.hasLocation() || !trackPoint.hasAltitude()) {
|
||||||
|
Log.d(TAG, "No altitude correction necessary.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (egm2008Correction == null || !egm2008Correction.canCorrect(trackPoint.getLocation())) {
|
||||||
|
try {
|
||||||
|
egm2008Correction = EGM2008Utils.createCorrection(context, trackPoint.getLocation());
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.e(TAG, "Could not load altitude correction for " + trackPoint, e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
trackPoint.setAltitude(Altitude.EGM2008.of(egm2008Correction.correctAltitude(trackPoint.getLocation())));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets the track points sampling states.
|
* Resets the track points sampling states.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public class EGM2008Utils {
|
|||||||
private EGM2008Utils() {
|
private EGM2008Utils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EGM2008Correction createEGM2008Correction(Context context, Location location) throws IOException {
|
public static EGM2008Correction createCorrection(Context context, Location location) throws IOException {
|
||||||
Indices indices = getIndices(location);
|
Indices indices = getIndices(location);
|
||||||
|
|
||||||
try (DataInputStream dataInputStream = new DataInputStream(context.getResources().openRawResource(EGM2008_5_DATA))) {
|
try (DataInputStream dataInputStream = new DataInputStream(context.getResources().openRawResource(EGM2008_5_DATA))) {
|
||||||
@@ -84,7 +84,7 @@ public class EGM2008Utils {
|
|||||||
protected final int v01;
|
protected final int v01;
|
||||||
protected final int v11;
|
protected final int v11;
|
||||||
|
|
||||||
public EGM2008Correction(Indices indices, DataInputStream dataInputStream) throws IOException {
|
private EGM2008Correction(Indices indices, DataInputStream dataInputStream) throws IOException {
|
||||||
this.indices = indices;
|
this.indices = indices;
|
||||||
|
|
||||||
v00 = getUndulationRaw(dataInputStream, indices);
|
v00 = getUndulationRaw(dataInputStream, indices);
|
||||||
|
|||||||
Reference in New Issue
Block a user