Ignore:
Timestamp:
2018-08-30T23:15:06+02:00 (6 years ago)
Author:
Don-vip
Message:

fix #16681 - Various enhancements for GPX correlation (patch by Bjoeni, modified)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImagesTest.java

    r14079 r14205  
    33
    44import static org.junit.Assert.assertEquals;
    5 import static org.junit.Assert.assertFalse;
    6 import static org.junit.Assert.assertTrue;
    75
    8 import java.util.Arrays;
    96import java.util.Collections;
    107
     
    129import org.junit.Rule;
    1310import org.junit.Test;
    14 import org.openstreetmap.josm.data.coor.CachedLatLon;
    1511import org.openstreetmap.josm.data.gpx.GpxData;
     12import org.openstreetmap.josm.data.gpx.GpxTimeOffset;
     13import org.openstreetmap.josm.data.gpx.GpxTimezone;
    1614import org.openstreetmap.josm.io.GpxReaderTest;
    1715import org.openstreetmap.josm.testutils.JOSMTestRules;
     
    4341
    4442    /**
    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     /**
    10243     * Tests automatic guessing of timezone/offset
    10344     * @throws Exception if an error occurs
     
    10950        i0.setExifTime(DateUtils.fromString("2016:01:03 11:59:54")); // 4 sec before start of GPX
    11051        i0.createTmp();
    111         assertEquals(Pair.create(Timezone.ZERO, Offset.seconds(-4)),
     52        assertEquals(Pair.create(GpxTimezone.ZERO, GpxTimeOffset.seconds(-4)),
    11253                CorrelateGpxWithImages.autoGuess(Collections.singletonList(i0), gpx));
    11354    }
Note: See TracChangeset for help on using the changeset viewer.