4

画像のすべてのメタデータ (緯度、経度、日時など) を実際に読み取る Java プログラムを作成しています。以下は、私が実行しているサンプルコードです。

public static void findLatLong(File jpg){
    try {
        Metadata metadata = ImageMetadataReader.readMetadata(jpg);    
        if (metadata.containsDirectory(GpsDirectory.class)) {
            GpsDirectory gpsDir =(GpsDirectory)metadata.getDirectory(GpsDirectory.class);
            GpsDescriptor gpsDesc = new GpsDescriptor(gpsDir);
            System.out.println("Latitude: " + gpsDesc.getGpsLatitudeDescription());
            System.out.println("Longitude : " + gpsDesc.getGpsLongitudeDescription());
            System.out.println("Date : " + gpsDesc.getGpsTimeStampDescription());
            System.out.println("Minute  : " + gpsDesc.getDegreesMinutesSecondsDescription());
        }else{
        //  System.out.println("----- Did not find GPS Information-------------for file " + jpg.getName() );
        }

    } catch (ImageProcessingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

出力: - 緯度:21.0°8.0 '22.99999999999998693 "経度:79.0°3.0' 12.99999994998"日付:14:16:30 UTC分:21.0°8.0 '22.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999

これはすべて学位形式だと思います。緯度と経度の実際の値を取得する方法を教えてください。また、適切な日付を取得します。

4

1 に答える 1

3

metadata-extractor >= 2.6.0 を使用している場合、新しいcom.drew.lang.GeoLocationクラス ( changelog ) を使用できます。

GpsDirectory gpsDirectory = metadata.getDirectory(GpsDirectory.class);
GeoLocation location = gpsDirectory.getGeoLocation();
double lat = location.getLatitude();
double lng = location.getLongitude();

そうでない場合、これは新しいクラスのソースで行われていることです:

   /**
     * Converts DMS (degrees-minutes-seconds) rational values, as given 
     * in {@link com.drew.metadata.exif.GpsDirectory},
     * into a single value in degrees, as a double.
     */
    @Nullable
    public static Double degreesMinutesSecondsToDecimal(
            @NotNull final Rational degs, @NotNull final Rational mins, 
            @NotNull final Rational secs, final boolean isNegative)  {

        double decimal = Math.abs(degs.doubleValue())
                + mins.doubleValue() / 60.0d
                + secs.doubleValue() / 3600.0d;

        if (Double.isNaN(decimal))
            return null;

        if (isNegative)
            decimal *= -1;

        return decimal;
    }

メソッドのパラメーターは次の場所から取得されます。

Rational[] latitudes = getRationalArray(GpsDirectory.TAG_LATITUDE);
Rational[] longitudes = getRationalArray(GpsDirectory.TAG_LONGITUDE);
String latitudeRef = getString(GpsDirectory.TAG_LATITUDE_REF);
String longitudeRef = getString(GpsDirectory.TAG_LONGITUDE_REF);
于 2013-03-12T03:27:57.933 に答える