Changeset 19455 in josm


Ignore:
Timestamp:
2026-01-05T14:30:23+01:00 (5 days ago)
Author:
stoecker
Message:

fix #24517 - patch by StephaneP - NullPointerException when trying to correlate images without ExifGpsTime - modifies a function prototype which seems unused by any plugins

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java

    r19426 r19455  
    552552        JLabel labelPosition = new JLabel(tr("Override position for: "));
    553553
    554         int numAll = yLayer.getSortedImgList(true, true).size();
    555         int numExif = numAll - yLayer.getSortedImgList(false, true).size();
    556         int numTagged = numAll - yLayer.getSortedImgList(true, false).size();
     554        int numAll = yLayer.getSortedImgList(true, true, imgTimeSource).size();
     555        int numExif = numAll - yLayer.getSortedImgList(false, true, imgTimeSource).size();
     556        int numTagged = numAll - yLayer.getSortedImgList(true, false, imgTimeSource).size();
    557557
    558558        cbExifImg = new JCheckBox(tr("Images with geo location in exif data ({0}/{1})", numExif, numAll));
     
    829829            yLayer.discardTmp();
    830830
     831            //Get how many images are present in the layer
     832            int totalImg = yLayer.getImages().size();
     833           
    831834            // Construct a list of images that have a date, and sort them on the date.
    832835            List<ImageEntry> dateImgLst = getSortedImgList();
     
    847850            return trn("<html>Matched <b>{0}</b> of <b>{1}</b> photo to GPX track.</html>",
    848851                    "<html>Matched <b>{0}</b> of <b>{1}</b> photos to GPX track.</html>",
    849                     dateImgLst.size(), lastNumMatched, dateImgLst.size());
     852                    totalImg, lastNumMatched, totalImg);
    850853        }
    851854    }
     
    10041007
    10051008    private List<ImageEntry> getSortedImgList() {
    1006         return yLayer.getSortedImgList(cbExifImg.isSelected(), cbTaggedImg.isSelected());
     1009        return yLayer.getSortedImgList(cbExifImg.isSelected(), cbTaggedImg.isSelected(), imgTimeSource);
    10071010    }
    10081011
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/EditImagesSequenceAction.java

    r19426 r19455  
    8080            yLayer.discardTmp();
    8181            // Construct a list of images that have a date, and sort them on the date.
    82             List<ImageEntry> dateImgLst = yLayer.getSortedImgList(true, true);
     82            List<ImageEntry> dateImgLst = yLayer.getSortedImgList(true, true, TimeSource.EXIFCAMTIME);
    8383            // Create a temporary copy for each image
    8484            dateImgLst.forEach(ie -> ie.createTmp().unflagNewGpsData());
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java

    r19369 r19455  
    4848import org.openstreetmap.josm.data.gpx.GpxImageEntry;
    4949import org.openstreetmap.josm.data.gpx.GpxTrack;
     50import org.openstreetmap.josm.data.gpx.TimeSource;
    5051import org.openstreetmap.josm.data.imagery.street_level.IImageEntry;
    5152import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
     
    978979     * @param exif also returns images with exif-gps info
    979980     * @param tagged also returns tagged images
     981     * @param gpsTime use GPS Time if true, instead of Camera RTC Time
    980982     * @return matching images
    981      */
    982     List<ImageEntry> getSortedImgList(boolean exif, boolean tagged) {
     983     * @since 19455 gpsTime was added
     984     */
     985    List<ImageEntry> getSortedImgList(boolean exif, boolean tagged, TimeSource timeSource) {
    983986        return data.getImages().stream()
    984                 .filter(GpxImageEntry::hasExifTime)
     987                .filter(timeSource == TimeSource.EXIFGPSTIME ? GpxImageEntry::hasExifGpsTime : GpxImageEntry::hasExifTime)
    985988                .filter(e -> e.getExifCoor() == null || exif)
    986989                .filter(e -> tagged || !e.isTagged() || e.getExifCoor() != null)
    987                 .sorted(Comparator.comparing(ImageEntry::getExifInstant))
     990                .sorted(timeSource == TimeSource.EXIFGPSTIME
     991                    ? Comparator.comparing(ImageEntry::getExifGpsInstant)
     992                    : Comparator.comparing(ImageEntry::getExifInstant))
    988993                .collect(toList());
    989994    }
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayerTest.java

    r19082 r19455  
    33
    44import static org.junit.jupiter.api.Assertions.assertThrows;
     5import static org.junit.jupiter.api.Assertions.assertEquals;
    56
     7import java.util.Arrays;
    68import java.util.Collections;
    79
    810import org.junit.jupiter.api.AfterEach;
    911import org.junit.jupiter.api.Test;
     12import org.openstreetmap.josm.data.gpx.TimeSource;
    1013import org.openstreetmap.josm.data.osm.DataSet;
    1114import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     
    1316import org.openstreetmap.josm.testutils.annotations.Main;
    1417import org.openstreetmap.josm.testutils.annotations.ThreadSync;
     18import org.openstreetmap.josm.tools.date.DateUtils;
    1519
    1620/**
     
    4246        assertThrows(IllegalArgumentException.class, () -> geoImageLayer.mergeFrom(osmDataLayer));
    4347    }
     48
     49    /**
     50     * Test that {@link GeoImageLayer#getSortedImgList} filters images without ExifGpsTime
     51     */
     52    @Test
     53    void testMissingGPSTimeStamp() {
     54        ImageEntry i1, i2;
     55        i1 = new ImageEntry();
     56        i1.setExifGpsTime(DateUtils.parseInstant("2016:01:03 12:00:00"));
     57        i2 = new ImageEntry();
     58        i2.setExifTime(DateUtils.parseInstant("2016:01:03 12:00:01"));
     59
     60        GeoImageLayer geoGpsImageLayer = new GeoImageLayer(Arrays.asList(i1, i2), null);
     61        assertEquals(1, geoGpsImageLayer.getSortedImgList(false, false, TimeSource.EXIFGPSTIME).size());
     62    }
     63
    4464}
Note: See TracChangeset for help on using the changeset viewer.