Ignore:
Timestamp:
2025-04-23T18:34:33+02:00 (12 months ago)
Author:
stoecker
Message:

see #24238 - support more EXIF data in image correlation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/ExifReader.java

    r19101 r19387  
    125125
    126126    /**
     127     * Returns the GPS date/time from the given JPEG file.
     128     * @param filename The JPEG file to read
     129     * @return The GPS date/time read in the EXIF section, or {@code null} if not found
     130     * @since 19387
     131     */
     132    public static Instant readGpsInstant(File filename) {
     133        try {
     134            final Metadata metadata = JpegMetadataReader.readMetadata(filename);
     135            final GpsDirectory dirGps = metadata.getFirstDirectoryOfType(GpsDirectory.class);
     136            return readGpsInstant(dirGps);
     137        } catch (JpegProcessingException | IOException e) {
     138            Logging.error(e);
     139        }
     140        return null;
     141    }
     142 
     143    /**
     144     * Returns the GPS date/time from the given JPEG file.
     145     * @param dirGps The EXIF GPS directory
     146     * @return The GPS date/time read in the EXIF section, or {@code null} if not found
     147     * @since 19387
     148     */
     149    public static Instant readGpsInstant(GpsDirectory dirGps) {
     150        if (dirGps != null) {
     151            try {
     152                Instant dateTimeStamp = dirGps.getGpsDate().toInstant();
     153                return dateTimeStamp;
     154            } catch (UncheckedParseException | DateTimeException e) {
     155                Logging.error(e);
     156            }
     157        }
     158        return null;
     159    }
     160 
     161    /**
    127162     * Returns the image orientation of the given JPEG file.
    128163     * @param filename The JPEG file to read
     
    219254    }
    220255
     256    /**
     257     * Returns the GPS track direction of the given JPEG file.
     258     * @param filename The JPEG file to read
     259     * @return The GPS track direction of the image when it was captures (in degrees between 0.0 and 359.99),
     260     * or {@code null} if not found
     261     * @since 19387
     262     */
     263    public static Double readGpsTrackDirection(File filename) {
     264        try {
     265            final Metadata metadata = JpegMetadataReader.readMetadata(filename);
     266            final GpsDirectory dirGps = metadata.getFirstDirectoryOfType(GpsDirectory.class);
     267            return readGpsTrackDirection(dirGps);
     268        } catch (JpegProcessingException | IOException e) {
     269            Logging.error(e);
     270        }
     271        return null;
     272    }
     273   
     274    /**
     275     * Returns the GPS track direction of the given EXIF GPS directory.
     276     * @param dirGps The EXIF GPS directory
     277     * @return The GPS track direction of the image when it was captured (in degrees between 0.0 and 359.99),
     278     * or {@code null} if missing or if {@code dirGps} is null
     279     * @since 19387
     280     */
     281    public static Double readGpsTrackDirection(GpsDirectory dirGps) {
     282        if (dirGps != null) {
     283            Rational trackDirection = dirGps.getRational(GpsDirectory.TAG_TRACK);
     284            if (trackDirection != null) {
     285                return trackDirection.doubleValue();
     286            }
     287        }
     288        return null;
     289    }
     290
    221291    private static double readAxis(GpsDirectory dirGps, int gpsTag, int gpsTagRef, char cRef) throws MetadataException {
    222292        double value;
     
    319389                }
    320390                return ele;
     391            }
     392        }
     393        return null;
     394    }
     395
     396    /**
     397     * Returns the GPS horizontal positionning error of the given JPEG file.
     398     * @param filename The JPEG file to read
     399     * @return The GPS horizontal positionning error of the camera when the image was captured (in m),
     400     *         or {@code null} if not found
     401     * @since 19387
     402     */
     403    public static Double readHpositioningError(File filename) {
     404        try {
     405            final Metadata metadata = JpegMetadataReader.readMetadata(filename);
     406            final GpsDirectory dirGps = metadata.getFirstDirectoryOfType(GpsDirectory.class);
     407            return readHpositioningError(dirGps);
     408        } catch (JpegProcessingException | IOException e) {
     409            Logging.error(e);
     410        }
     411        return null;
     412    }
     413
     414    /**
     415     * Returns the GPS horizontal positionning error of the given EXIF GPS directory.
     416     * @param dirGps The EXIF GPS directory
     417     * @return The GPS horizontal positionning error of the camera when the image was captured (in m),
     418     *         or {@code null} if missing or if {@code dirGps} is null
     419     * @since 19387
     420     */
     421    public static Double readHpositioningError(GpsDirectory dirGps) {
     422        if (dirGps != null) {
     423            Double hposerr = dirGps.getDoubleObject(GpsDirectory.TAG_H_POSITIONING_ERROR);
     424            if (hposerr != null) {
     425                return hposerr.doubleValue();
     426            }
     427        }
     428        return null;
     429    }
     430
     431    /**
     432     * Returns the GPS differential mode of the given JPEG file.
     433     * @param filename The JPEG file to read
     434     * @return The GPS differential mode of the camera when the image was captured,
     435     * <ul>
     436     *  <li>0 : no differential correction</li>
     437     *  <li>1 : differential correction</li>
     438     *  <li>or {@code null} if not found</li>
     439     * </ul>
     440     * @since 19387
     441     */
     442    public static Integer readGpsDiffMode(File filename) {
     443        try {
     444            final Metadata metadata = JpegMetadataReader.readMetadata(filename);
     445            final GpsDirectory dirGps = metadata.getFirstDirectoryOfType(GpsDirectory.class);
     446            return readGpsDiffMode(dirGps);
     447        } catch (JpegProcessingException | IOException e) {
     448            Logging.error(e);
     449        }
     450        return null;
     451    }
     452
     453    /**
     454     * Returns the GPS differential mode of the given EXIF GPS directory.
     455     * @param dirGps The EXIF GPS directory
     456     * @return The GPS differential mode of the camera when the image was captured,
     457     * <ul>
     458     *  <li>0 : no differential correction</li>
     459     *  <li>1 : differential correction</li>
     460     *  <li>or {@code null} if missing or if {@code dirGps} is null</li>
     461     * </ul>
     462     * @since 19387
     463     */   
     464    public static Integer readGpsDiffMode(GpsDirectory dirGps) {
     465        if (dirGps != null) {
     466            Integer gpsDiffMode = dirGps.getInteger(GpsDirectory.TAG_DIFFERENTIAL);
     467            if (gpsDiffMode != null) {
     468                return gpsDiffMode.intValue();
     469            }
     470        }
     471        return null;
     472    }
     473
     474    /**
     475     * Returns the GPS 2d/3d mode of the given JPEG file.
     476     * @param filename The JPEG file to read
     477     * @return The GPS 2d/3d mode of the camera when the image was captured,
     478     * <ul>
     479     *  <li>2 : 2d mode</li>
     480     *  <li>2 : 3d mode</li>
     481     *  <li>or {@code null} if not found</li>
     482     * </ul>
     483     * @since 19387
     484     */
     485    public static Integer readGpsMeasureMode(File filename) {
     486        try {
     487            final Metadata metadata = JpegMetadataReader.readMetadata(filename);
     488            final GpsDirectory dirGps = metadata.getFirstDirectoryOfType(GpsDirectory.class);
     489            return readGpsMeasureMode(dirGps);
     490        } catch (JpegProcessingException | IOException e) {
     491            Logging.error(e);
     492        }
     493        return null;
     494    }
     495
     496    /**
     497     * Returns the GPS 2d/3d mode of the given EXIF GPS directory.
     498     * @param dirGps The EXIF GPS directory
     499     * @return The 2d/3d mode of the camera when the image was captured,
     500     * <ul>
     501     *  <li>2 : 2d mode</li>
     502     *  <li>3 : 3d mode</li>
     503     *  <li>or {@code null} if missing or if {@code dirGps} is null</li>
     504     * </ul>
     505     * @since 19387
     506     */   
     507    public static Integer readGpsMeasureMode(GpsDirectory dirGps) {
     508        if (dirGps != null) {
     509            Integer gps2d3dMode = dirGps.getInteger(GpsDirectory.TAG_MEASURE_MODE);
     510            if (gps2d3dMode != null) {
     511                return gps2d3dMode.intValue();
     512            }
     513        }
     514        return null;
     515    }
     516
     517    /**
     518     * Returns the GPS DOP value of the given JPEG file.
     519     * @param filename The JPEG file to read
     520     * @return The GPS DOP value of the camera when the image was captured,
     521     *         or {@code null} if not found
     522     * @since 19387
     523     */
     524    public static Double readGpsDop(File filename) {
     525        try {
     526            final Metadata metadata = JpegMetadataReader.readMetadata(filename);
     527            final GpsDirectory dirGps = metadata.getFirstDirectoryOfType(GpsDirectory.class);
     528            return readGpsDop(dirGps);
     529        } catch (JpegProcessingException | IOException e) {
     530            Logging.error(e);
     531        }
     532        return null;
     533    }
     534
     535    /**
     536     * Returns the GPS DOP value of the given EXIF GPS directory.
     537     * @param dirGps The EXIF GPS directory
     538     * @return The GPS DOP value of the camera when the image was captured,
     539     *         or {@code null} if missing or if {@code dirGps} is null
     540     * @since 19387
     541     */
     542    public static Double readGpsDop(GpsDirectory dirGps) {
     543        if (dirGps != null) {
     544            Double gpsDop = dirGps.getDoubleObject(GpsDirectory.TAG_DOP);
     545            if (gpsDop != null) {
     546                return gpsDop.doubleValue();
     547            }
     548        }
     549        return null;
     550    }
     551
     552    /**
     553     * Returns the GPS datum value of the given JPEG file.
     554     * @param filename The JPEG file to read
     555     * @return The GPS datum value of the camera when the image was captured,
     556     *         or {@code null} if not found
     557     * @since 19387
     558     */
     559    public static String readGpsDatum(File filename) {
     560        try {
     561            final Metadata metadata = JpegMetadataReader.readMetadata(filename);
     562            final GpsDirectory dirGps = metadata.getFirstDirectoryOfType(GpsDirectory.class);
     563            return readGpsDatum(dirGps);
     564        } catch (JpegProcessingException | IOException e) {
     565            Logging.error(e);
     566        }
     567        return null;
     568    }
     569
     570    /**
     571     * Returns the GPS datum value of the given EXIF GPS directory.
     572     * @param dirGps The EXIF GPS directory
     573     * @return The GPS datum value of the camera when the image was captured,
     574     *         or {@code null} if missing or if {@code dirGps} is null
     575     * @since 19387
     576     */
     577    public static String readGpsDatum(GpsDirectory dirGps) {
     578        if (dirGps != null) {
     579            String gpsDatum = dirGps.getString(GpsDirectory.TAG_MAP_DATUM);
     580            if (gpsDatum != null) {
     581                return gpsDatum.toString();
     582            }
     583        }
     584        return null;
     585    }
     586
     587    /**
     588     * Return the GPS processing method of the given JPEG file.
     589     * @param filename The JPEG file to read
     590     * @return The GPS processing method. Possible values from the EXIF specs are:
     591     * <ul>
     592     * <li>GPS</li>
     593     * <li>QZSS</li>
     594     * <li>GALILEO</li>
     595     * <li>GLONASS</li>
     596     * <li>BEIDOU</li>
     597     * <li>NAVIC</li>
     598     * <li>CELLID</li>
     599     * <li>WLAN</li>
     600     * <li>MANUAL</li>
     601     * </ul>
     602     * Other values, and combined space separated values are possible too.
     603     * or {@code null} if missing
     604     * @since 19387
     605     */
     606    public static String readGpsProcessingMethod(File filename) {
     607        try {
     608            final Metadata metadata = JpegMetadataReader.readMetadata(filename);
     609            final GpsDirectory dirGps = metadata.getFirstDirectoryOfType(GpsDirectory.class);
     610            return readGpsProcessingMethod(dirGps);
     611        } catch (JpegProcessingException | IOException e) {
     612            Logging.error(e);
     613        }
     614        return null;
     615    }
     616
     617    /**
     618     * Return the GPS processing method of the given EXIF GPS directory.
     619     * @param dirGps The EXIF GPS directory
     620     * @return The GPS processing method. Possible values from the EXIF specs are:
     621     * <ul>
     622     * <li>GPS</li>
     623     * <li>QZSS</li>
     624     * <li>GALILEO</li>
     625     * <li>GLONASS</li>
     626     * <li>BEIDOU</li>
     627     * <li>NAVIC</li>
     628     * <li>CELLID</li>
     629     * <li>WLAN</li>
     630     * <li>MANUAL</li>
     631     * </ul>
     632     * Other values, and combined space separated values are possible too.
     633     * or {@code null} if missing or if {@code dirGps} is null
     634     * @since 19387
     635     */
     636    public static String readGpsProcessingMethod(GpsDirectory dirGps) {
     637        if (dirGps != null) {
     638            String gpsProcessingMethod = dirGps.getDescription(GpsDirectory.TAG_PROCESSING_METHOD);
     639            if (gpsProcessingMethod != null) {
     640                return gpsProcessingMethod.toString();
    321641            }
    322642        }
Note: See TracChangeset for help on using the changeset viewer.