source: josm/trunk/test/unit/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImagesTest.java@ 13256

Last change on this file since 13256 was 13256, checked in by Don-vip, 6 years ago

fix #15701 - CorrelateGpxWithImages: Test newGpsData, speed, elevation, gpsTime set by matchGpxTrack() (patch by holgermappt)

  • Property svn:eol-style set to native
File size: 5.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.layer.geoimage;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertFalse;
6import static org.junit.Assert.assertTrue;
7
8import java.util.Arrays;
9import java.util.Collections;
10import java.util.TimeZone;
11
12import org.junit.BeforeClass;
13import org.junit.Rule;
14import org.junit.Test;
15import org.openstreetmap.josm.data.coor.CachedLatLon;
16import org.openstreetmap.josm.data.gpx.GpxData;
17import org.openstreetmap.josm.io.GpxReaderTest;
18import org.openstreetmap.josm.testutils.JOSMTestRules;
19import org.openstreetmap.josm.tools.Pair;
20import org.openstreetmap.josm.tools.date.DateUtils;
21import org.openstreetmap.josm.tools.date.DateUtilsTest;
22
23import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
24
25/**
26 * Unit tests of {@link CorrelateGpxWithImages} class.
27 */
28public class CorrelateGpxWithImagesTest {
29
30 /**
31 * Setup test.
32 */
33 @Rule
34 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
35 public JOSMTestRules test = new JOSMTestRules();
36
37 /**
38 * Setup test.
39 */
40 @BeforeClass
41 public static void setUp() {
42 DateUtilsTest.setTimeZone(TimeZone.getTimeZone("UTC"));
43 }
44
45 /**
46 * Tests matching of images to a GPX track.
47 * @throws Exception if the track cannot be parsed
48 */
49 @Test
50 public void testMatchGpxTrack() throws Exception {
51 final GpxData gpx = GpxReaderTest.parseGpxData("data_nodist/2094047.gpx");
52 assertEquals(4, gpx.tracks.size());
53 assertEquals(1, gpx.tracks.iterator().next().getSegments().size());
54 assertEquals(185, gpx.tracks.iterator().next().getSegments().iterator().next().getWayPoints().size());
55
56 final ImageEntry ib = new ImageEntry();
57 ib.setExifTime(DateUtils.fromString("2016:01:03 11:54:58")); // 5 minutes before start of GPX
58 ib.createTmp();
59 final ImageEntry i0 = new ImageEntry();
60 i0.setExifTime(DateUtils.fromString("2016:01:03 11:59:54")); // 4 sec before start of GPX
61 i0.createTmp();
62 final ImageEntry i1 = new ImageEntry();
63 i1.setExifTime(DateUtils.fromString("2016:01:03 12:04:01"));
64 i1.createTmp();
65 final ImageEntry i2 = new ImageEntry();
66 i2.setExifTime(DateUtils.fromString("2016:01:03 12:04:57"));
67 i2.createTmp();
68 final ImageEntry i3 = new ImageEntry();
69 i3.setExifTime(DateUtils.fromString("2016:01:03 12:05:05"));
70 i3.createTmp();
71
72 assertEquals(4, CorrelateGpxWithImages.matchGpxTrack(Arrays.asList(ib, i0, i1, i2, i3), gpx, 0));
73 assertEquals(new CachedLatLon(47.19286847859621, 8.79732714034617), i0.getPos()); // start of track
74 assertEquals(new CachedLatLon(47.196979885920882, 8.79541271366179), i1.getPos()); // exact match
75 assertEquals(new CachedLatLon(47.197319911792874, 8.792139580473304), i3.getPos()); // exact match
76 assertEquals(new CachedLatLon((47.197131179273129 + 47.197186248376966) / 2, (8.792974585667253 + 8.792809881269932) / 2),
77 i2.getPos()); // interpolated
78 assertFalse(ib.hasNewGpsData());
79 assertTrue(i0.hasNewGpsData());
80 assertTrue(i1.hasNewGpsData());
81 assertTrue(i2.hasNewGpsData());
82 assertTrue(i3.hasNewGpsData());
83 // First waypoint has no speed in matchGpxTrack(). Speed is calculated
84 // and not taken from GPX track.
85 assertEquals(null, ib.getSpeed());
86 assertEquals(null, i0.getSpeed());
87 assertEquals(new Double(11.675317966018756), i1.getSpeed(), 0.000001);
88 assertEquals(new Double(24.992418392716967), i2.getSpeed(), 0.000001);
89 assertEquals(new Double(27.307968754679223), i3.getSpeed(), 0.000001);
90 assertEquals(null, ib.getElevation());
91 assertEquals(new Double(471.86), i0.getElevation(), 0.000001);
92 assertEquals(new Double(489.29), i1.getElevation(), 0.000001);
93 assertEquals(new Double((490.40 + 489.75) / 2), i2.getElevation(), 0.000001);
94 assertEquals(new Double(486.368333333), i3.getElevation(), 0.000001);
95 assertEquals(null, ib.getGpsTime());
96 assertEquals(DateUtils.fromString("2016:01:03 11:59:54"), i0.getGpsTime()); // original time is kept
97 assertEquals(DateUtils.fromString("2016:01:03 12:04:01"), i1.getGpsTime());
98 assertEquals(DateUtils.fromString("2016:01:03 12:04:57"), i2.getGpsTime());
99 assertEquals(DateUtils.fromString("2016:01:03 12:05:05"), i3.getGpsTime());
100 }
101
102 /**
103 * Tests automatic guessing of timezone/offset
104 * @throws Exception if an error occurs
105 */
106 @Test
107 public void testAutoGuess() throws Exception {
108 final GpxData gpx = GpxReaderTest.parseGpxData("data_nodist/2094047.gpx");
109 final ImageEntry i0 = new ImageEntry();
110 i0.setExifTime(DateUtils.fromString("2016:01:03 11:59:54")); // 4 sec before start of GPX
111 i0.createTmp();
112 assertEquals(Pair.create(Timezone.ZERO, Offset.seconds(-4)),
113 CorrelateGpxWithImages.autoGuess(Collections.singletonList(i0), gpx));
114 }
115}
Note: See TracBrowser for help on using the repository browser.