Examples of GpsDirectory


Examples of 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) {
View Full Code Here

Examples of com.drew.metadata.exif.GpsDirectory

public class HeadingExtractor {
    private static final LumifyLogger LOGGER = LumifyLoggerFactory.getLogger(HeadingExtractor.class);

    public static Double getImageHeading(Metadata metadata) {
        GpsDirectory gpsDir = metadata.getDirectory(GpsDirectory.class);
        if (gpsDir != null) {
            //TODO. Assumes true direction for IMG_DIRECTION. Can check TAG_GPS_IMG_DIRECTION_REF to be more specific.
            try {
                Double imageHeading = gpsDir.getDouble(GpsDirectory.TAG_GPS_IMG_DIRECTION);
                return imageHeading;
            } catch (MetadataException e) {
                LOGGER.debug("getDouble(TAG_GPS_IMAGE_DIRECTION) threw MetadataException when attempting to" +
                        "retrieve GPS Heading.");
            }
View Full Code Here

Examples of com.drew.metadata.exif.GpsDirectory

        Wpt result = null;
        try{
            Metadata meta = (new ExifReader(jpeg)).extract();
            boolean hasGpsDirectory = meta.containsDirectory(GpsDirectory.class);
            if(hasGpsDirectory){
                GpsDirectory gps = (GpsDirectory) meta.getDirectory(GpsDirectory.class);
                if(gps.hasErrors()){
                    System.err.println("Warning: GPS directory has errors");
                    java.util.Iterator it = gps.getErrors();
                    while(it.hasNext()){
                        System.out.println(it.next());
                    }
                }
                java.util.Iterator tagiter = gps.getTagIterator();
                int i = 0;
                while(tagiter.hasNext()){
                    tagiter.next();
                    i++;
                }
View Full Code Here

Examples of com.drew.metadata.exif.GpsDirectory

    public static Geolocation getGeolocation(@Nullable final byte[] imageBytes) throws ImageProcessingException, IOException {
        if (imageBytes != null && imageBytes.length > 0) {

            final Metadata metadata = ImageMetadataReader.readMetadata(new BufferedInputStream(new ByteArrayInputStream(imageBytes)), false);
            if (metadata != null) {
                final GpsDirectory gpsDirectory = metadata.getDirectory(GpsDirectory.class);
                if (gpsDirectory != null) {
                    return new GeolocationImpl(gpsDirectory);
                }
            }
        }
View Full Code Here

Examples of com.drew.metadata.exif.GpsDirectory

        for (File file : files)
        {
            // Read all metadata from the image
            Metadata metadata = ImageMetadataReader.readMetadata(file);
            // See whether it has GPS data
            GpsDirectory gpsDirectory = metadata.getDirectory(GpsDirectory.class);
            if (gpsDirectory == null)
                continue;
            // Try to read out the location, making sure it's non-zero
            GeoLocation geoLocation = gpsDirectory.getGeoLocation();
            if (geoLocation == null || geoLocation.isZero())
                continue;
            // Add to our collection for use below
            photoLocations.add(new PhotoLocation(geoLocation, file));
        }
View Full Code Here

Examples of com.drew.metadata.exif.GpsDirectory

        for (File file : files)
        {
            // Read all metadata from the image
            Metadata metadata = ImageMetadataReader.readMetadata(file);
            // See whether it has GPS data
            GpsDirectory gpsDirectory = metadata.getDirectory(GpsDirectory.class);
            if (gpsDirectory == null)
                continue;
            // Try to read out the location, making sure it's non-zero
            GeoLocation geoLocation = gpsDirectory.getGeoLocation();
            if (geoLocation == null || geoLocation.isZero())
                continue;
            // Add to our collection for use below
            photoLocations.add(new PhotoLocation(geoLocation, file));
        }
View Full Code Here

Examples of com.drew.metadata.exif.GpsDirectory

     * @since 6209
     */
    public static LatLon readLatLon(File filename) {
        try {
            final Metadata metadata = JpegMetadataReader.readMetadata(filename);
            final GpsDirectory dirGps = metadata.getDirectory(GpsDirectory.class);
            return readLatLon(dirGps);
        } catch (JpegProcessingException e) {
            Main.error(e);
        } catch (IOException e) {
            Main.error(e);
View Full Code Here

Examples of com.drew.metadata.exif.GpsDirectory

     * @since 6209
     */
    public static Double readDirection(File filename) {
        try {
            final Metadata metadata = JpegMetadataReader.readMetadata(filename);
            final GpsDirectory dirGps = metadata.getDirectory(GpsDirectory.class);
            return readDirection(dirGps);
        } catch (JpegProcessingException e) {
            Main.error(e);
        } catch (IOException e) {
            Main.error(e);
View Full Code Here

Examples of com.drew.metadata.exif.GpsDirectory

     */
    private static void extractExif(ImageEntry e) {

        Metadata metadata;
        Directory dirExif;
        GpsDirectory dirGps;

        try {
            metadata = JpegMetadataReader.readMetadata(e.getFile());
            dirExif = metadata.getDirectory(ExifIFD0Directory.class);
            dirGps = metadata.getDirectory(GpsDirectory.class);
        } catch (CompoundException | IOException p) {
            e.setExifCoor(null);
            e.setPos(null);
            return;
        }

        try {
            if (dirExif != null) {
                int orientation = dirExif.getInt(ExifIFD0Directory.TAG_ORIENTATION);
                e.setExifOrientation(orientation);
            }
        } catch (MetadataException ex) {
            Main.debug(ex.getMessage());
        }

        if (dirGps == null) {
            e.setExifCoor(null);
            e.setPos(null);
            return;
        }

        try {
            double ele = dirGps.getDouble(GpsDirectory.TAG_GPS_ALTITUDE);
            int d = dirGps.getInt(GpsDirectory.TAG_GPS_ALTITUDE_REF);
            if (d == 1) {
                ele *= -1;
            }
            e.setElevation(ele);
        } catch (MetadataException ex) {
            Main.debug(ex.getMessage());
        }

        try {
            LatLon latlon = ExifReader.readLatLon(dirGps);
            e.setExifCoor(latlon);
            e.setPos(e.getExifCoor());

        } catch (Exception ex) { // (other exceptions, e.g. #5271)
            Main.error("Error reading EXIF from file: "+ex);
            e.setExifCoor(null);
            e.setPos(null);
        }

        try {
            Double direction = ExifReader.readDirection(dirGps);
            if (direction != null) {
                e.setExifImgDir(direction.doubleValue());
            }
        } catch (Exception ex) { // (CompoundException and other exceptions, e.g. #5271)
            Main.debug(ex.getMessage());
        }

        // Time and date. We can have these cases:
        // 1) GPS_TIME_STAMP not set -> date/time will be null
        // 2) GPS_DATE_STAMP not set -> use EXIF date or set to default
        // 3) GPS_TIME_STAMP and GPS_DATE_STAMP are set
        int[] timeStampComps = dirGps.getIntArray(GpsDirectory.TAG_GPS_TIME_STAMP);
        if (timeStampComps != null) {
            int gpsHour = timeStampComps[0];
            int gpsMin = timeStampComps[1];
            int gpsSec = timeStampComps[2];
            Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));

            // We have the time. Next step is to check if the GPS date stamp is set.
            // dirGps.getString() always succeeds, but the return value might be null.
            String dateStampStr = dirGps.getString(GpsDirectory.TAG_GPS_DATE_STAMP);
            if (dateStampStr != null && dateStampStr.matches("^\\d+:\\d+:\\d+$")) {
                String[] dateStampComps = dateStampStr.split(":");
                cal.set(Calendar.YEAR, Integer.parseInt(dateStampComps[0]));
                cal.set(Calendar.MONTH, Integer.parseInt(dateStampComps[1]) - 1);
                cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(dateStampComps[2]));
View Full Code Here

Examples of com.drew.metadata.exif.GpsDirectory

                    attributes.add(new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_DATETIME_CREATED.getTypeID(), ExifParserModuleFactory.getModuleName(), date.getTime() / 1000));
                }
            }

            // GPS Stuff
            GpsDirectory gpsDir = metadata.getDirectory(GpsDirectory.class);
            if (gpsDir != null) {
                GeoLocation loc = gpsDir.getGeoLocation();
                if (loc != null) {
                    double latitude = loc.getLatitude();
                    double longitude = loc.getLongitude();
                    attributes.add(new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_GEO_LATITUDE.getTypeID(), ExifParserModuleFactory.getModuleName(), latitude));
                    attributes.add(new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_GEO_LONGITUDE.getTypeID(), ExifParserModuleFactory.getModuleName(), longitude));
                }

                Rational altitude = gpsDir.getRational(GpsDirectory.TAG_GPS_ALTITUDE);
                if (altitude != null) {
                    attributes.add(new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_GEO_ALTITUDE.getTypeID(), ExifParserModuleFactory.getModuleName(), altitude.doubleValue()));
                }
            }
View Full Code Here
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.