Package io.lumify.imageMetadataHelper

Source Code of io.lumify.imageMetadataHelper.GeoPointExtractor

package io.lumify.imageMetadataHelper;

import com.drew.lang.GeoLocation;
import com.drew.metadata.Metadata;
import com.drew.metadata.MetadataException;
import com.drew.metadata.exif.GpsDirectory;
import org.securegraph.type.GeoPoint;

public class GeoPointExtractor {

    public static GeoPoint getGeoPoint(Metadata metadata) {
        GpsDirectory gpsDir = metadata.getDirectory(GpsDirectory.class);
        if (gpsDir != null) {
            GeoLocation geoLocation = gpsDir.getGeoLocation();
            if (geoLocation != null) {
                Double latitude = geoLocation.getLatitude();
                Double longitude = geoLocation.getLongitude();
                Double altitude = null;
                try {
                    altitude = gpsDir.getDouble(GpsDirectory.TAG_GPS_ALTITUDE);
                } catch (MetadataException e) {
                    //No code needed. Altitude is already null.
                }

                if (latitude != null && latitude != 0 && longitude != null && longitude != 0) {
                    if (altitude != null && altitude != 0) {
                        GeoPoint geoPoint = new GeoPoint(latitude, longitude, altitude);
                        return geoPoint;
                    } else {
                        GeoPoint geoPoint = new GeoPoint(latitude, longitude);
                        return geoPoint;
                    }
                }
            }

        }
        return null;
    }

}
TOP

Related Classes of io.lumify.imageMetadataHelper.GeoPointExtractor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.