Changeset 6128 in josm


Ignore:
Timestamp:
2013-08-09T18:39:40+02:00 (11 years ago)
Author:
bastiK
Message:

see #8895 - add most recent changes

File:
1 edited

Legend:

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

    r6127 r6128  
    6565import com.drew.imaging.jpeg.JpegMetadataReader;
    6666import com.drew.lang.CompoundException;
    67 import com.drew.lang.GeoLocation;
    6867import com.drew.lang.Rational;
    6968import com.drew.metadata.Directory;
     
    509508    private static void extractExif(ImageEntry e) {
    510509
     510        double deg;
     511        double min, sec;
     512        double lon, lat;
    511513        Metadata metadata;
    512514        Directory dirExif;
     
    550552
    551553        try {
    552             GeoLocation location = dirGps.getGeoLocation();
    553             if (location != null) {
    554                 e.setExifCoor(new LatLon(location.getLatitude(), location.getLongitude()));
    555                 e.setPos(e.getExifCoor());
     554            // longitude
     555
     556            Rational[] components = dirGps.getRationalArray(GpsDirectory.TAG_GPS_LONGITUDE);
     557            if (components != null) {
     558                deg = components[0].doubleValue();
     559                min = components[1].doubleValue();
     560                sec = components[2].doubleValue();
     561
     562                if (Double.isNaN(deg) && Double.isNaN(min) && Double.isNaN(sec))
     563                    throw new IllegalArgumentException();
     564
     565                lon = (Double.isNaN(deg) ? 0 : deg + (Double.isNaN(min) ? 0 : (min / 60)) + (Double.isNaN(sec) ? 0 : (sec / 3600)));
     566
     567                if (dirGps.getString(GpsDirectory.TAG_GPS_LONGITUDE_REF).charAt(0) == 'W') {
     568                    lon = -lon;
     569                }
    556570            } else {
    557571                // Try to read lon/lat as double value (Nonstandard, created by some cameras -> #5220)
    558                 try {
    559                     Double longitude = dirGps.getDouble(GpsDirectory.TAG_GPS_LONGITUDE);
    560                     Double latitude = dirGps.getDouble(GpsDirectory.TAG_GPS_LATITUDE);
    561    
    562                     // Store values
    563    
    564                     e.setExifCoor(new LatLon(latitude, longitude));
    565                     e.setPos(e.getExifCoor());
    566                 } catch (CompoundException ex) {
    567                     e.setExifCoor(null);
    568                     e.setPos(null);
    569                 }
    570             }
     572                lon = dirGps.getDouble(GpsDirectory.TAG_GPS_LONGITUDE);
     573            }
     574
     575            // latitude
     576
     577            components = dirGps.getRationalArray(GpsDirectory.TAG_GPS_LATITUDE);
     578            if (components != null) {
     579                deg = components[0].doubleValue();
     580                min = components[1].doubleValue();
     581                sec = components[2].doubleValue();
     582
     583                if (Double.isNaN(deg) && Double.isNaN(min) && Double.isNaN(sec))
     584                    throw new IllegalArgumentException();
     585
     586                lat = (Double.isNaN(deg) ? 0 : deg + (Double.isNaN(min) ? 0 : (min / 60)) + (Double.isNaN(sec) ? 0 : (sec / 3600)));
     587
     588                if (Double.isNaN(lat))
     589                    throw new IllegalArgumentException();
     590
     591                if (dirGps.getString(GpsDirectory.TAG_GPS_LATITUDE_REF).charAt(0) == 'S') {
     592                    lat = -lat;
     593                }
     594            } else {
     595                lat = dirGps.getDouble(GpsDirectory.TAG_GPS_LATITUDE);
     596            }
     597
     598            // Store values
     599
     600            e.setExifCoor(new LatLon(lat, lon));
     601            e.setPos(e.getExifCoor());
     602
    571603        } catch (Exception ex) { // (other exceptions, e.g. #5271)
    572604            System.err.println("Error reading EXIF from file: "+ex);
Note: See TracChangeset for help on using the changeset viewer.