Changeset 19426 in josm for trunk


Ignore:
Timestamp:
2025-07-12T18:15:02+02:00 (4 months ago)
Author:
stoecker
Message:

fix #24347 - Add gps time choice on image/gpx correlation - patch by StephaneP

Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxImageCorrelation.java

    r19390 r19426  
    7777        final GpxImageDatumSettings datumSettings = settings.getDatumSettings();
    7878        final long offset = settings.getOffset();
     79        final TimeSource imgTimeSource = settings.getImgTimeSource();
    7980
    8081        boolean isFirst = true;
     
    145146                    }
    146147                    WayPoint nextWp = i < size - 1 ? wps.get(i + 1) : null;
    147                     ret += matchPoints(images, prevWp, prevWpTime, curWp, curWpTime, offset,
     148                    ret += matchPoints(images, prevWp, prevWpTime, curWp, curWpTime, imgTimeSource, offset,
    148149                                       interpolate, tagTime, nextWp, dirpos, datumSettings);
    149150                    prevWp = curWp;
     
    153154        }
    154155        if (trkTag && prevWp != null) {
    155             ret += matchPoints(images, prevWp, prevWpTime, prevWp, prevWpTime, offset,
     156            ret += matchPoints(images, prevWp, prevWpTime, prevWp, prevWpTime, imgTimeSource, offset,
    156157                               false, trkTagTime, null, dirpos, datumSettings);
    157158        }
     
    362363                                        WayPoint curWp,
    363364                                        long curWpTime,
     365                                        TimeSource imgTimeSource,
    364366                                        long offset,
    365367                                        boolean interpolate,
     
    376378            i = images.size() - 1;
    377379        } else {
    378             i = getLastIndexOfListBefore(images, curWpTime);
     380            i = getLastIndexOfListBefore(images, curWpTime, imgTimeSource);
    379381        }
    380382
     
    427429                final GpxImageEntry curImg = images.get(i);
    428430                final GpxImageEntry curTmp = curImg.getTmp();
    429                 final long time = curImg.getExifInstant().toEpochMilli();
     431                final long time = curImg.getTimeSourceInstant(imgTimeSource).toEpochMilli();
    430432                if ((!isLast && time > curWpTime) || time < prevWpTime) {
    431433                    break;
     
    460462            while (i >= 0) {
    461463                final GpxImageEntry curImg = images.get(i);
    462                 final long imgTime = curImg.getExifInstant().toEpochMilli();
     464                final long imgTime = curImg.getTimeSourceInstant(imgTimeSource).toEpochMilli();
    463465                if (imgTime < prevWpTime) {
    464466                    break;
     
    548550                    }
    549551
    550                     curTmp.setGpsTime(curImg.getExifInstant().minusMillis(offset));
     552                    curTmp.setGpsTime(curImg.getTimeSourceInstant(imgTimeSource).minusMillis(offset));
    551553                    curTmp.flagNewGpsData();
    552554                    curImg.tmpUpdated();
     
    579581     * @return index of last image before given time
    580582     */
    581     private static int getLastIndexOfListBefore(List<? extends GpxImageEntry> images, long searchedTime) {
     583    private static int getLastIndexOfListBefore(List<? extends GpxImageEntry> images, long searchedTime, TimeSource imgTimeSource) {
    582584        int lstSize = images.size();
    583585
    584586        // No photos or the first photo taken is later than the search period
    585         if (lstSize == 0 || searchedTime < images.get(0).getExifInstant().toEpochMilli())
     587        if (lstSize == 0 || searchedTime < images.get(0).getTimeSourceInstant(imgTimeSource).toEpochMilli())
    586588            return -1;
    587589
    588590        // The search period is later than the last photo
    589         if (searchedTime > images.get(lstSize - 1).getExifInstant().toEpochMilli())
     591        if (searchedTime > images.get(lstSize - 1).getTimeSourceInstant(imgTimeSource).toEpochMilli())
    590592            return lstSize-1;
    591593
     
    596598        while (endIndex - startIndex > 1) {
    597599            curIndex = (endIndex + startIndex) / 2;
    598             if (searchedTime > images.get(curIndex).getExifInstant().toEpochMilli()) {
     600            if (searchedTime > images.get(curIndex).getTimeSourceInstant(imgTimeSource).toEpochMilli()) {
    599601                startIndex = curIndex;
    600602            } else {
     
    602604            }
    603605        }
    604         if (searchedTime < images.get(endIndex).getExifInstant().toEpochMilli())
     606        if (searchedTime < images.get(endIndex).getTimeSourceInstant(imgTimeSource).toEpochMilli())
    605607            return startIndex;
    606608
    607609        // This final loop is to check if photos with the exact same EXIF time follows
    608         while ((endIndex < (lstSize - 1)) && (images.get(endIndex).getExifInstant().toEpochMilli()
    609                 == images.get(endIndex + 1).getExifInstant().toEpochMilli())) {
     610        while ((endIndex < (lstSize - 1)) && (images.get(endIndex).getTimeSourceInstant(imgTimeSource).toEpochMilli()
     611                == images.get(endIndex + 1).getTimeSourceInstant(imgTimeSource).toEpochMilli())) {
    610612            endIndex++;
    611613        }
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxImageCorrelationSettings.java

    r19387 r19426  
    1212    private final long offset;
    1313    private final boolean forceTags;
     14    private final TimeSource imgTimeSource;
    1415    private final GpxImageDirectionPositionSettings directionPositionSettings;
    1516    private final GpxImageDatumSettings datumSettings;
     
    2122     */
    2223    public GpxImageCorrelationSettings(long offset, boolean forceTags) {
    23         this(offset, forceTags,
     24        this(offset, forceTags, TimeSource.EXIFCAMTIME,
    2425        new GpxImageDirectionPositionSettings(false, 0, false, 0, 0, 0),
    2526        new GpxImageDatumSettings(false, null)
     
    3132     * @param offset offset in milliseconds
    3233     * @param forceTags force tagging of all photos, otherwise prefs are used
     34     * @param imgTimeSource select image clock source:
     35     *                      "exifCamTime" for camera internal clock
     36     *                      "exifGpsTime for the GPS clock of the camera
    3337     * @param directionPositionSettings direction/position settings
     38     * @since 19426 @imgTimeSource was added
    3439     */
    35     public GpxImageCorrelationSettings(long offset, boolean forceTags,
     40    public GpxImageCorrelationSettings(long offset, boolean forceTags, TimeSource imgTimeSource,
    3641            GpxImageDirectionPositionSettings directionPositionSettings) {
    37         this(offset, forceTags, directionPositionSettings,
     42        this(offset, forceTags, imgTimeSource, directionPositionSettings,
    3843        new GpxImageDatumSettings(false, null));
    3944    }
     
    4348     * @param offset offset in milliseconds
    4449     * @param forceTags force tagging of all photos, otherwise prefs are used
     50     * @param imgTimeSource select image clock source:
     51     *                      "exifCamTime" for camera internal clock
     52     *                      "exifGpsTime for the GPS clock of the camera
    4553     * @param directionPositionSettings direction/position settings
    4654     * @param datumSettings GPS datum settings
    4755     * @since 19387 @datumSettings was added
     56     * @since 19426 @imgTimeSource was added
    4857     */
    49     public GpxImageCorrelationSettings(long offset, boolean forceTags,
     58    public GpxImageCorrelationSettings(long offset, boolean forceTags, TimeSource imgTimeSource,
    5059            GpxImageDirectionPositionSettings directionPositionSettings,
    5160            GpxImageDatumSettings datumSettings) {
    5261        this.offset = offset;
    5362        this.forceTags = forceTags;
     63        this.imgTimeSource = imgTimeSource;
    5464        this.directionPositionSettings = Objects.requireNonNull(directionPositionSettings);
    5565        this.datumSettings = Objects.requireNonNull(datumSettings);
     
    7080    public boolean isForceTags() {
    7181        return forceTags;
     82    }
     83
     84    /**
     85     * Return the selected image clock source, which is camera internal time, or GPS time
     86     * @return the clock source
     87     * @since 19426
     88     */
     89    public TimeSource getImgTimeSource() {
     90        return imgTimeSource;
    7291    }
    7392
     
    92111    public String toString() {
    93112        return "[offset=" + offset + ", forceTags=" + forceTags
     113                + ", clock source=" + imgTimeSource
    94114                + ", directionPositionSettings=" + directionPositionSettings
    95115                + ", datumSettings=" + datumSettings + ']';
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxImageEntry.java

    r19391 r19426  
    335335    public boolean hasExifGpsTime() {
    336336        return exifGpsTime != null;
     337    }
     338
     339    /**
     340     * Return the time value selected with the parameter.
     341     * @param timeSource the wanted time value, exifCamTime or exifGpsTime
     342     * @return exifInstant or exifGpsInstant value
     343     * @since 19426
     344     */
     345    @Override
     346    public Instant getTimeSourceInstant(TimeSource timeSource) {
     347        switch (timeSource) {
     348            case EXIFGPSTIME:
     349                return getExifGpsInstant();
     350            case EXIFCAMTIME:
     351                return getExifInstant();
     352        }
     353        return null;
    337354    }
    338355
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java

    r19388 r19426  
    3333import javax.swing.AbstractAction;
    3434import javax.swing.BorderFactory;
     35import javax.swing.ButtonGroup;
    3536import javax.swing.DefaultComboBoxModel;
    3637import javax.swing.JButton;
     
    3940import javax.swing.JOptionPane;
    4041import javax.swing.JPanel;
     42import javax.swing.JRadioButton;
    4143import javax.swing.JSeparator;
    4244import javax.swing.SwingConstants;
     
    5759import org.openstreetmap.josm.data.gpx.GpxTimeOffset;
    5860import org.openstreetmap.josm.data.gpx.GpxTimezone;
     61import org.openstreetmap.josm.data.gpx.TimeSource;
    5962import org.openstreetmap.josm.data.gpx.WayPoint;
    6063import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
     
    8992    private static JosmComboBoxModel<GpxDataWrapper> gpxModel;
    9093    private static boolean forceTags;
     94    private static TimeSource imgTimeSource;
    9195
    9296    private final transient GeoImageLayer yLayer;
     
    254258    private JosmTextField tfTimezone;
    255259    private JosmTextField tfOffset;
     260    private JRadioButton rbTimeFromCamera;
     261    private JRadioButton rbTimeFromGps;
    256262    private JCheckBox cbExifImg;
    257263    private JCheckBox cbTaggedImg;
     
    485491    }
    486492
     493    // CHECKSTYLE.OFF: ExecutableStatementCount
    487494    @Override
    488495    public void actionPerformed(ActionEvent ae) {
     
    521528        tfOffset.setText(delta.formatOffset());
    522529
     530        // Image Time/Clock source choice
     531        rbTimeFromCamera = new JRadioButton(tr("Camera clock"));
     532        rbTimeFromCamera.setSelected(true);
     533        rbTimeFromGps = new JRadioButton(tr("Camera GPS clock"));       
     534        ButtonGroup timeSourceGroup = new ButtonGroup();
     535        timeSourceGroup.add(rbTimeFromCamera);
     536        timeSourceGroup.add(rbTimeFromGps);
     537
    523538        JButton buttonViewGpsPhoto = new JButton(tr("<html>Use photo of an accurate clock,<br>e.g. GPS receiver display</html>"));
    524539        buttonViewGpsPhoto.setIcon(ImageProvider.get("clock"));
     
    586601        gbc.gridx = 3;
    587602        panelTf.add(buttonAdjust, gbc);
     603
     604        // Image time source choice
     605        gbc = GBC.eol();
     606        gbc.gridx = 0;
     607        gbc.gridy = y++;
     608        panelTf.add(new JLabel(tr("Image time source:")), gbc);
     609
     610        gbc = GBC.eol();
     611        gbc.gridx = 1;
     612        gbc.gridy = y++;
     613        panelTf.add(rbTimeFromCamera, gbc);
     614
     615        gbc = GBC.eol();
     616        gbc.gridx = 1;
     617        gbc.gridy = y++;
     618        panelTf.add(rbTimeFromGps, gbc);
    588619
    589620        gbc = GBC.eol().grid(0, y++).fill(GridBagConstraints.HORIZONTAL).insets(0, 12, 0, 0);
     
    652683        tfTimezone.getDocument().addDocumentListener(statusBarUpdater);
    653684        tfOffset.getDocument().addDocumentListener(statusBarUpdater);
     685        rbTimeFromCamera.addItemListener(statusBarUpdaterWithRepaint);
     686        rbTimeFromGps.addItemListener(statusBarUpdaterWithRepaint);
    654687        cbExifImg.addItemListener(statusBarUpdaterWithRepaint);
    655688        cbTaggedImg.addItemListener(statusBarUpdaterWithRepaint);
     
    682715        }
    683716    }
     717    // CHECKSTYLE.ON: ExecutableStatementCount
    684718
    685719    public GpxImageDatumSettings getSettings() {
     
    784818            }
    785819
     820            // Set image time source from the radio button status
     821            if (rbTimeFromGps.isSelected()) {
     822                imgTimeSource = TimeSource.EXIFGPSTIME;
     823            } else {
     824                imgTimeSource = TimeSource.EXIFCAMTIME;
     825            }
     826
    786827            // The selection of images we are about to correlate may have changed.
    787828            // So reset all images.
     
    800841            lastNumMatched = GpxImageCorrelation.matchGpxTrack(dateImgLst, selGpx.data,
    801842                    pDirectionPosition.isVisible() ?
    802                             new GpxImageCorrelationSettings(offsetMs, forceTags, pDirectionPosition.getSettings(),
     843                            new GpxImageCorrelationSettings(offsetMs, forceTags, imgTimeSource, pDirectionPosition.getSettings(),
    803844                                                            new GpxImageDatumSettings(cbAddGpsDatum.isSelected(), tfDatum.getText())) :
    804845                            new GpxImageCorrelationSettings(offsetMs, forceTags));
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/EditImagesSequenceAction.java

    r18078 r19426  
    1717import org.openstreetmap.josm.data.gpx.GpxImageCorrelation;
    1818import org.openstreetmap.josm.data.gpx.GpxImageCorrelationSettings;
     19import org.openstreetmap.josm.data.gpx.TimeSource;
    1920import org.openstreetmap.josm.gui.ExtendedDialog;
    2021import org.openstreetmap.josm.gui.MainApplication;
     
    8384            dateImgLst.forEach(ie -> ie.createTmp().unflagNewGpsData());
    8485            GpxImageCorrelation.matchGpxTrack(dateImgLst, yLayer.getFauxGpxData(),
    85                             new GpxImageCorrelationSettings(0, false, pDirectionPosition.getSettings()));
     86                            new GpxImageCorrelationSettings(0, false, TimeSource.EXIFCAMTIME, pDirectionPosition.getSettings()));
    8687            yLayer.updateBufferAndRepaint();
    8788        }
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageMetadata.java

    r19391 r19426  
    1212
    1313import org.openstreetmap.josm.data.coor.ILatLon;
     14import org.openstreetmap.josm.data.gpx.TimeSource;
    1415import org.openstreetmap.josm.data.imagery.street_level.Projections;
    1516
     
    115116     */
    116117    boolean hasExifGpsTime();
     118
     119    /**
     120     * Return the time value selected with the parameter.
     121     * @param timeSource the wanted time value, exifCamTime or exifGpsTime
     122     * @return exifInstant or exifGpsInstant value
     123     * @since 19426
     124     */
     125    Instant getTimeSourceInstant(TimeSource timeSource);
    117126
    118127    /**
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/RemoteEntry.java

    r19387 r19426  
    1818
    1919import org.openstreetmap.josm.data.coor.ILatLon;
     20import org.openstreetmap.josm.data.gpx.TimeSource;
    2021import org.openstreetmap.josm.data.imagery.street_level.IImageEntry;
    2122import org.openstreetmap.josm.data.imagery.street_level.Projections;
     
    362363
    363364    @Override
     365    public Instant getTimeSourceInstant(TimeSource timeSource) {
     366        return this.getTimeSourceInstant(timeSource);
     367    }
     368
     369    @Override
    364370    public Instant getExifGpsInstant() {
    365371        return this.exifGpsTime;
Note: See TracChangeset for help on using the changeset viewer.