1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.layer.geoimage;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 |
|
---|
6 | import java.util.Arrays;
|
---|
7 | import java.util.TimeZone;
|
---|
8 |
|
---|
9 | import org.junit.BeforeClass;
|
---|
10 | import org.junit.Test;
|
---|
11 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
12 | import org.openstreetmap.josm.data.gpx.GpxData;
|
---|
13 | import org.openstreetmap.josm.io.GpxReaderTest;
|
---|
14 | import org.openstreetmap.josm.tools.date.DateUtils;
|
---|
15 | import org.openstreetmap.josm.tools.date.DateUtilsTest;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Unit tests of {@link CorrelateGpxWithImagesTest} class.
|
---|
19 | */
|
---|
20 | public class CorrelateGpxWithImagesTest {
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Setup test.
|
---|
24 | */
|
---|
25 | @BeforeClass
|
---|
26 | public static void setUp() {
|
---|
27 | DateUtilsTest.setTimeZone(TimeZone.getTimeZone("UTC"));
|
---|
28 | }
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * Tests matching of images to a GPX track.
|
---|
32 | * @throws Exception if the track cannot be parsed
|
---|
33 | */
|
---|
34 | @Test
|
---|
35 | public void testMatchGpxTrack() throws Exception {
|
---|
36 | final GpxData gpx = GpxReaderTest.parseGpxData("data_nodist/2094047.gpx");
|
---|
37 | assertEquals(4, gpx.tracks.size());
|
---|
38 | assertEquals(1, gpx.tracks.iterator().next().getSegments().size());
|
---|
39 | assertEquals(185, gpx.tracks.iterator().next().getSegments().iterator().next().getWayPoints().size());
|
---|
40 |
|
---|
41 | final ImageEntry i0 = new ImageEntry();
|
---|
42 | i0.setExifTime(DateUtils.fromString("2016:01:03 11:59:54")); // 4 sec before start of GPX
|
---|
43 | i0.createTmp();
|
---|
44 | final ImageEntry i1 = new ImageEntry();
|
---|
45 | i1.setExifTime(DateUtils.fromString("2016:01:03 12:04:01"));
|
---|
46 | i1.createTmp();
|
---|
47 | final ImageEntry i2 = new ImageEntry();
|
---|
48 | i2.setExifTime(DateUtils.fromString("2016:01:03 12:04:57"));
|
---|
49 | i2.createTmp();
|
---|
50 | final ImageEntry i3 = new ImageEntry();
|
---|
51 | i3.setExifTime(DateUtils.fromString("2016:01:03 12:05:05"));
|
---|
52 | i3.createTmp();
|
---|
53 |
|
---|
54 | assertEquals(4, CorrelateGpxWithImages.matchGpxTrack(Arrays.asList(i0, i1, i2, i3), gpx, 0));
|
---|
55 | assertEquals(new LatLon(47.19286847859621, 8.79732714034617), i0.getPos()); // start of track
|
---|
56 | assertEquals(new LatLon(47.196979885920882, 8.79541271366179), i1.getPos()); // exact match
|
---|
57 | assertEquals(new LatLon(47.197319911792874, 8.792139580473304), i3.getPos()); // exact match
|
---|
58 | assertEquals(new LatLon((47.197131179273129 + 47.197186248376966) / 2, (8.792974585667253 + 8.792809881269932) / 2),
|
---|
59 | i2.getPos()); // interpolated
|
---|
60 | }
|
---|
61 | }
|
---|