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

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

see #16550 - use UTC by default for GPX timestamps

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