Ticket #11710: 11710-V2.patch

File 11710-V2.patch, 7.9 KB (added by Bjoeni, 5 years ago)
  • src/org/openstreetmap/josm/data/gpx/GpxImageEntry.java

    ### Eclipse Workspace Patch 1.0
    #P josm-11710
     
    571571            elevation = tmp.elevation;
    572572            gpsTime = tmp.gpsTime;
    573573            exifImgDir = tmp.exifImgDir;
    574             isNewGpsData = tmp.isNewGpsData;
     574            isNewGpsData = isNewGpsData || tmp.isNewGpsData;
    575575            tmp = null;
    576576        }
    577577        tmpUpdated();
  • src/org/openstreetmap/josm/data/gpx/GpxImageCorrelation.java

     
    229229                    break;
    230230                }
    231231                long tagms = TimeUnit.MINUTES.toMillis(tagTime);
    232                 if (curTmp.getPos() == null &&
     232                if (!curTmp.hasNewGpsData() &&
    233233                        (Math.abs(time - curWpTime) <= tagms
    234234                        || Math.abs(prevWpTime - time) <= tagms)) {
    235235                    if (prevWp != null && time < curWpTime - half) {
     
    255255                if (imgTime < prevWpTime) {
    256256                    break;
    257257                }
    258                 if (curTmp.getPos() == null) {
     258                if (!curTmp.hasNewGpsData()) {
    259259                    // The values of timeDiff are between 0 and 1, it is not seconds but a dimensionless variable
    260260                    double timeDiff = (double) (imgTime - prevWpTime) / Math.abs(curWpTime - prevWpTime);
    261261                    curTmp.setPos(prevWp.getCoor().interpolate(curWp.getCoor(), timeDiff));
  • src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java

     
    10901090            // Construct a list of images that have a date, and sort them on the date.
    10911091            List<ImageEntry> dateImgLst = getSortedImgList();
    10921092            // Create a temporary copy for each image
    1093             for (ImageEntry ie : dateImgLst) {
    1094                 ie.createTmp();
    1095                 ie.getTmp().setPos(null);
    1096             }
     1093            dateImgLst.forEach(i -> {
     1094                i.createTmp();
     1095                i.getTmp().unflagNewGpsData();
     1096            });
    10971097
    10981098            GpxDataWrapper selGpx = selectedGPX(false);
    10991099            if (selGpx == null)
  • test/unit/org/openstreetmap/josm/data/gpx/GpxImageCorrelationTest.java

     
    6464        i0.createTmp();
    6565        final GpxImageEntry i1 = new GpxImageEntry();
    6666        i1.setExifTime(DateUtils.parseInstant("2016:01:03 12:04:01"));
     67        i1.setPos(new CachedLatLon(2, 3)); //existing position inside the track, should always be overridden
    6768        i1.createTmp();
    6869        final GpxImageEntry i2 = new GpxImageEntry();
    6970        i2.setExifTime(DateUtils.parseInstant("2016:01:03 12:04:57"));
     
    8081        final GpxImageEntry i6 = new GpxImageEntry(); //between two tracks, closer to second (more than 1 minute from any track)
    8182        i6.setExifTime(DateUtils.parseInstant("2016:01:03 12:07:45"));
    8283        i6.createTmp();
     84        final GpxImageEntry i7 = new GpxImageEntry();
     85        i7.setExifTime(DateUtils.parseInstant("2021:01:01 00:00:00"));
     86        i7.setPos(new CachedLatLon(1, 2)); //existing position outside the track, should never be null (either overridden or keeping old position, see #11710)
     87        i7.createTmp();
    8388
    84         List<GpxImageEntry> images = Arrays.asList(ib, i0, i1, i2, i3, i4, i5, i6);
     89        List<GpxImageEntry> images = Arrays.asList(ib, i0, i1, i2, i3, i4, i5, i6, i7);
    8590
    8691        // TEST #1: default settings
    8792        // tag images within 2 minutes to tracks/segments, interpolate between segments only
     
    98103                i5.getPos()); // tagged to last WP of first track, because closer and within 2 min (default setting)
    99104        assertEquals(new CachedLatLon(47.20138901844621, 8.774476982653141),
    100105                i6.getPos()); // tagged to first WP of second track, because closer and within 2 min (default setting)
    101         assertFalse(ib.hasNewGpsData());
     106        assertEquals(new CachedLatLon(1, 2), i7.getPos()); //existing EXIF data is kept
     107        assertFalse(ib.hasNewGpsData() || i7.hasNewGpsData());
    102108        assertTrue(i0.hasNewGpsData() && i1.hasNewGpsData() && i2.hasNewGpsData() && i3.hasNewGpsData()
    103109                && i4.hasNewGpsData() && i5.hasNewGpsData() && i6.hasNewGpsData());
    104110        // First waypoint has no speed in matchGpxTrack(). Speed is calculated
     
    147153
    148154        // TEST #3: Disable all interpolation and allow tagging within 1 minute of a track. i0-i5 are tagged.
    149155        // i6 will not be tagged, because it's 68 seconds away from the next waypoint in either direction
     156        // i7 will keep the old position
    150157
    151158        s.putBoolean("geoimage.trk.tag", true);
    152159        s.putBoolean("geoimage.trk.tag.time", true);
     
    165172        assertEquals(new CachedLatLon(47.197568312311816, 8.790292849679897), i4.getPos());
    166173        assertEquals(new CachedLatLon(47.19819249585271, 8.78536943346262), i5.getPos());
    167174        assertEquals(null, i6.getPos());
     175        assertEquals(new CachedLatLon(1, 2), i7.getPos());
    168176
    169177        clearTmp(images);
    170178
    171179        // TEST #4: Force tagging (parameter forceTags=true, no change of configuration). All images will be tagged
    172180        // i5-i6 will now be interpolated, therefore it will have an elevation and different coordinates than in tests above
     181        // i7 will be at the end of the track
    173182
    174         assertEquals(8, GpxImageCorrelation.matchGpxTrack(images, gpx, 0, true));
     183        assertEquals(9, GpxImageCorrelation.matchGpxTrack(images, gpx, 0, true));
    175184        assertEquals(new CachedLatLon(47.19286847859621, 8.79732714034617), ib.getPos());
    176185        assertEquals(new CachedLatLon(47.19286847859621, 8.79732714034617), i0.getPos());
    177186        assertEquals(new CachedLatLon(47.196979885920882, 8.79541271366179), i1.getPos());
     
    184193        assertEquals(Double.valueOf(447.894014085), i5.getElevation(), 0.000001);
    185194        assertEquals(Double.valueOf(437.395070423), i6.getElevation(), 0.000001);
    186195
     196        assertEquals(new CachedLatLon(47.20126815140247, 8.77192972227931), i7.getPos());
     197
    187198        clearTmp(images);
    188199
    189200        // TEST #5: Force tagging (parameter forceTags=false, but configuration changed).
     
    201212        s.putBoolean("geoimage.seg.int.time", false);
    202213        s.putBoolean("geoimage.seg.int.dist", false);
    203214
    204         assertEquals(8, GpxImageCorrelation.matchGpxTrack(images, gpx, 0, false));
     215        assertEquals(9, GpxImageCorrelation.matchGpxTrack(images, gpx, 0, false));
    205216        assertEquals(new CachedLatLon(47.19286847859621, 8.79732714034617), ib.getPos());
    206217        assertEquals(new CachedLatLon(47.19286847859621, 8.79732714034617), i0.getPos());
    207218        assertEquals(new CachedLatLon(47.196979885920882, 8.79541271366179), i1.getPos());
     
    214225        assertEquals(Double.valueOf(447.894014085), i5.getElevation(), 0.000001);
    215226        assertEquals(Double.valueOf(437.395070423), i6.getElevation(), 0.000001);
    216227
     228        assertEquals(new CachedLatLon(47.20126815140247, 8.77192972227931), i7.getPos());
     229
    217230        clearTmp(images);
    218231
    219232        // TEST #6: Disable tagging but allow interpolation when tracks are less than 500m apart. i0-i4 are tagged.