Package net.sourceforge.gpstools.gpx

Examples of net.sourceforge.gpstools.gpx.Wpt


        Date d = from.getTime();
        to.setTime(d);
    }

    public Wpt copyWpt(Wpt pt){
        Wpt result = new Wpt();
        copyProperties(pt, result);
        return result;
    }
View Full Code Here


        copyProperties(pt, result);
        return result;
    }

    private TimeZone getTimeZone(BoundsType bounds) throws TimeZoneBoundaryException, GeonamesException{
            WptType pt = new Wpt();
            pt.setLat(bounds.getMinlat());
            pt.setLon(bounds.getMinlon());
            final TimeZone result = getTimeZone(pt);
            if(result == null){
                return null;
            }
            pt.setLon(bounds.getMaxlon());
            TimeZone check = getTimeZone(pt);
            if(!result.equals(check)){
                throw new TimeZoneBoundaryException(bounds);
            }
            pt.setLat(bounds.getMaxlat());
            check = getTimeZone(pt);
            if(!result.equals(check)){
                throw new TimeZoneBoundaryException(bounds);
            }
            pt.setLon(bounds.getMinlon());
            check = getTimeZone(pt);
            if(!result.equals(check)){
                throw new TimeZoneBoundaryException(bounds);
            }
            return result;
View Full Code Here

            System.out.println(hgt.getElevation(lat, lon));
        } finally {
            hgt.close();
        }

        WptType pt = new Wpt();
        pt.setLat(lat);
        pt.setLon(lon);
        WptType[] wpts = new WptType[] { pt };
        try {
            GPXUtils.getInstance().setEle(wpts);
            System.out.println(pt.getEle());
        } catch (GeonamesException ex) {
            System.out.println(ex.getMessage());
        }
    }
View Full Code Here

        return result;
    }

    @Override
    public Wpt readGPSTag(File jpeg) throws IOException, ParseException{
        Wpt result = null;
        InputStream fip = null;
        int oldDebugLevel = mediautil.gen.Log.debugLevel;
        mediautil.gen.Log.debugLevel = mediautil.gen.Log.LEVEL_NONE;
        try{
            fip = new BufferedInputStream(new FileInputStream(jpeg)); // No need to buffer
View Full Code Here

    private static Wpt wptFromGpsTag(IFD gps) throws MetadataException, ParseException{
        if(gps == null){
            return null;
        }

        Wpt result = new Wpt();
        Rational[] r3 = new Rational[3];

        /* map datum */
        Entry e = gps.getEntry(Exif.GPSMapDatum, 0);
        if(e == null){
            warn("GPS datum missing. Assuming WGS84.");
        } else {
            Object value = e.getValue(0);
            String svalue = String.valueOf(value);
            if(value == null || svalue.equals("")){
                System.err.println("Warning: GPS datum missing. Assuming WGS84.");
            } else if(!svalue.toUpperCase().replaceAll("[^0-9A-Z]", "").equals("WGS84")){
                throw new MetadataException("GPS datum is " + value.toString() +
                    ". Currently only coordinates in the WGS84 "+
                    "map datum can be handled.");
            }
        }

        /* latitude */
        e = gps.getEntry(Exif.GPSLatitude, 0);
        if(e == null){
           throw new MetadataException("GPS latitude missing.");
        }
        r3 = getRationalTripleValue(e, r3);
        e = gps.getEntry(Exif.GPSLatitudeRef, 0);
        if(e == null){
        String sysprop = System.getProperty("DefaultGPSLatitudeRef");
        char s0 = (sysprop == null || sysprop.length() == 0)
            ? 'X'
            : sysprop.toUpperCase().charAt(0);
        if(s0 != 'N' && s0 != 'S'){
            throw new MetadataException("GPS latitude found but GPS latitude reference missing or invalid.\n"+
                "    To use the GPS latitude information set the DefaultGPSLatitudeRef system property to N or S, e. g.\n"+
                "    java -DDefaultGPSLatitudeRef=N -jar gpsdings.jar ...");
        }
        result.setLat(asBigDecimalDegrees(r3, String.valueOf(s0)));
        } else {
        result.setLat(asBigDecimalDegrees(r3, String.valueOf(e.getValue(0))));
    }

        /* longitude */
        e = gps.getEntry(Exif.GPSLongitude, 0);
        if(e == null){
           throw new MetadataException("GPS longtude missing.");
        }
        r3 = getRationalTripleValue(e, r3);
        e = gps.getEntry(Exif.GPSLongitudeRef, 0);
        if(e == null){
        String sysprop = System.getProperty("DefaultGPSLongitudeRef");
        final char s0 = (sysprop == null || sysprop.length() == 0)
            ? 'X'
            : sysprop.toUpperCase().charAt(0);
        if(s0 != 'E' && s0 != 'W'){
            throw new MetadataException("GPS longitude found but GPS longitude reference missing or invalid.\n"+
                "    To use the GPS longitude information set the DefaultGPSLongitudeRef system property to W or E, e. g.\n"+
                "    java -DDefaultGPSLongitudeRef=E -jar gpsdings.jar ...");
        }
        result.setLon(asBigDecimalDegrees(r3, String.valueOf(s0)));
        } else {
        result.setLon(asBigDecimalDegrees(r3, String.valueOf(e.getValue(0))));
    }


        /* elevation */
        if(gps.getEntry(Exif.GPSAltitude, 0) != null){
            double alti = 1;
            if (gps.getEntry(Exif.GPSAltitudeRef, 0) == null){
                warn("GPSAltitudeRef missing. Assuming above sea level.");
            } else {
                e = gps.getEntry(Exif.GPSAltitudeRef, 0);
                alti *= ((Integer) e.getValue(0)).intValue() * (-2) + 1; // 0 -> 1 && 1 -> -1
                if (Math.abs(alti) != 1 ){
                    alti = 1;
                    System.err.printf("WARNING: illegal GPSAltitudeRef %d. Assuming above sea level.\n",
                        ((Integer) e.getValue(0)).intValue());
                }
            }

            e = gps.getEntry(Exif.GPSAltitude, 0);
            alti *= ((Rational) e.getValue(0)).floatValue();
            result.setEle(new BigDecimal(alti));
        }

        /* dateTime */
        if(gps.getEntry(Exif.GPSTimeStamp, 0) != null &&
            gps.getEntry(Exif.GPSDateStamp, 0) != null){
            e = gps.getEntry(Exif.GPSTimeStamp, 0);
            r3 = getRationalTripleValue(e, r3);
            long millis = Math.round(asDouble(r3, 3.6e6));

            e = gps.getEntry(Exif.GPSDateStamp, 0);
            Date d = null;
            if(e.getType() == Exif.ASCII){
            try{
                d = AbstractExecExifWriter.parseExifDate(String.valueOf(e.getValue(0)));
                d = new Date(d.getTime() + millis);
                result.setTime(d);
            } catch (ParseException ex){
                System.err.println(ex);
            }
            }
        if(d == null) {
View Full Code Here

        }
    }

    @Override
    public Wpt readGPSTag(File jpeg) throws IOException, ParseException{
        Wpt result = null;
        try{
            final TiffDirectory gpsIfd =
                SanselanExifReader.getExif(jpeg).findDirectory(
                    TiffConstants.DIRECTORY_TYPE_GPS);
            result = wptFromGpsTag(gpsIfd);
View Full Code Here

    ImageReadException, ImageWriteException{
        if(gpsIfd == null){
            return null;
        }

        Wpt result = new Wpt();
        Number[] r3;
        TiffField e;

        /* map datum */
        e = gpsIfd.findField(TiffConstants.GPS_TAG_GPS_MAP_DATUM);
        if(e == null){
            warn("GPS datum missing. Assuming WGS84.");
        } else {
            String svalue = (String) e.getValue();
            if(svalue.equals("")){
                System.err.println("Warning: GPS datum missing. Assuming WGS84.");
            } else if(!svalue.toUpperCase().replaceAll("[^0-9A-Z]", "").equals("WGS84")){
                throw new MetadataException("GPS datum is " + svalue +
                    ". Currently only coordinates in the WGS84 "+
                    "map datum can be handled.");
            }
        }

        /* latitude */
        e = gpsIfd.findField(TiffConstants.GPS_TAG_GPS_LATITUDE);
        if(e == null){
           throw new MetadataException("GPS latitude missing.");
        }
        r3 = (Number[]) e.getValue();
        e = gpsIfd.findField(TiffConstants.GPS_TAG_GPS_LATITUDE_REF);
        if(e == null){
            String sysprop = System.getProperty("DefaultGPSLatitudeRef");
            char s0 = (sysprop == null || sysprop.length() == 0)
            ? 'X'
            : sysprop.toUpperCase().charAt(0);
            if(s0 != 'N' && s0 != 'S'){
                throw new MetadataException("GPS latitude found but GPS latitude reference missing or invalid.\n"+
                    "    To use the GPS latitude information set the DefaultGPSLatitudeRef system property to N or S, e. g.\n"+
                    "    java -DDefaultGPSLatitudeRef=N -jar gpsdings.jar ...");
            }
            result.setLat(asBigDecimalDegrees(r3, String.valueOf(s0)));
        } else {
            result.setLat(asBigDecimalDegrees(r3, (String) e.getValue()));
        }

        /* longitude */
        e = gpsIfd.findField(TiffConstants.GPS_TAG_GPS_LONGITUDE);
        if(e == null){
           throw new MetadataException("GPS longitude missing.");
        }
        r3 = (Number[]) e.getValue();
        e = gpsIfd.findField(TiffConstants.GPS_TAG_GPS_LONGITUDE_REF);
        if(e == null){
            String sysprop = System.getProperty("DefaultGPSLongitudeRef");
            final char s0 = (sysprop == null || sysprop.length() == 0)
            ? 'X'
            : sysprop.toUpperCase().charAt(0);
            if(s0 != 'E' && s0 != 'W'){
                throw new MetadataException("GPS longitude found but GPS longitude reference missing or invalid.\n"+
                    "    To use the GPS longitude information set the DefaultGPSLongitudeRef system property to W or E, e. g.\n"+
                    "    java -DDefaultGPSLongitudeRef=E -jar gpsdings.jar ...");
            }
            result.setLon(asBigDecimalDegrees(r3, String.valueOf(s0)));
        } else {
            result.setLon(asBigDecimalDegrees(r3, (String) e.getValue()));
        }

        /* elevation */
        e = gpsIfd.findField(TiffConstants.GPS_TAG_GPS_ALTITUDE);
        if(e != null){
            double alti = ((Number) e.getValue()).doubleValue();
            e = gpsIfd.findField(TiffConstants.GPS_TAG_GPS_ALTITUDE_REF);
            if (e == null){
                warn("GPSAltitudeRef missing. Assuming above sea level.");
            } else {
                int altref = ((Number) e.getValue()).intValue() * (-2) + 1; // 0 -> 1 && 1 -> -1
                if (Math.abs(altref) != 1 ){
                    System.err.printf("WARNING: illegal GPSAltitudeRef %d. Assuming above sea level.\n",
                        altref);
                    altref = 1;
                }
                alti *= altref;
            }
            result.setEle(new BigDecimal(alti));
        }

        /* dateTime */
        e = gpsIfd.findField(TiffConstants.GPS_TAG_GPS_TIME_STAMP);
        if(e != null){
            r3 = (Number[]) e.getValue();
            long millis = Math.round(asDouble(r3, 3.6e6));
            e = gpsIfd.findField(TiffConstants.GPS_TAG_GPS_DATE_STAMP);
            if (e != null){
                Date d = null;
                try{
                    d = AbstractExecExifWriter.parseExifDate((String) e.getValue());
                    d = new Date(d.getTime() + millis);
                    result.setTime(d);
                } catch (ParseException ex){
                    System.err.println(ex);
                }
                if(d == null) {
                    warn("Exif GPSDateStamp is not in ASCII YYYY:MM:DD format.\n" +
View Full Code Here

    }

    public synchronized Wpt getWpt(Date date)
            throws FunctionEvaluationException {
        final double millis = date.getTime();
        final Wpt wpt = new Wpt();
        wpt.setTime(date);
        wpt.setLat(new BigDecimal(fLati.value(millis)));
        wpt.setLon(new BigDecimal(fLongi.value(millis)));
        wpt.setEle(new BigDecimal(fEle.value(millis)));
        return wpt;
    }
View Full Code Here

        ex.initCause(t);
        return ex;
    }

    public Wpt readGPSTag(File jpeg) throws IOException, ParseException{
        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++;
                }
                if(i == 0){
                    hasGpsDirectory = false;
                } else {
                    result = wptFromGpsTag(gps);
                }
            }
            if (!hasGpsDirectory) {
                System.err.println("Warning no dedicated GPS directory found. Looking for GPS info in main Exif directory.");
                Directory dir = meta.getDirectory(ExifDirectory.class);
                if(dir.hasErrors()){
                    System.err.println("Warning: Exif directory has errors.");
                    java.util.Iterator it = dir.getErrors();
                    while(it.hasNext()){
                        System.out.println(it.next());
                    }
                }
                result = wptFromGpsTag(dir);
            }
        } catch (JpegProcessingException ex){
            throw toIOException(ex, jpeg);
        catch (MetadataException ex){
            throw toIOException(ex, jpeg);
        }
        if(result == null){
            throw new ParseException("No GPS information found in " + jpeg.getPath(),0);
        } else {
            try{
                result.setTime(readOriginalUTCTime(jpeg));
            } catch (Exception ex){
                throw new Error(ex);
            }
        }
        return result;
View Full Code Here

        }
        return result;
    }

    private static Wpt wptFromGpsTag(Directory gps) throws MetadataException{
        Wpt result = null;
        if(!gps.containsTag(GpsDirectory.TAG_GPS_LATITUDE)){
           throw new MetadataException("GPS latitude missing.");
        }
        if(!gps.containsTag(GpsDirectory.TAG_GPS_LATITUDE_REF)){
           throw new MetadataException("GPS latitude reference missing.");
        }
        if(!gps.containsTag(GpsDirectory.TAG_GPS_LONGITUDE)){
           throw new MetadataException("GPS longitude missing.");
        }
        if(!gps.containsTag(GpsDirectory.TAG_GPS_LONGITUDE_REF)){
           throw new MetadataException("GPS longitude reference missing.");
        }
        result = new Wpt();
        result.setLat(
                    asBigDecimal(
                    gps.getRationalArray(GpsDirectory.TAG_GPS_LATITUDE),
                    gps.getString(GpsDirectory.TAG_GPS_LATITUDE_REF)));
        result.setLon(
                    asBigDecimal(
                    gps.getRationalArray(GpsDirectory.TAG_GPS_LONGITUDE),
                    gps.getString(GpsDirectory.TAG_GPS_LONGITUDE_REF)));
        if(gps.containsTag(GpsDirectory.TAG_GPS_ALTITUDE)){
            result.setEle(new BigDecimal(
                    gps.getDouble(GpsDirectory.TAG_GPS_ALTITUDE)));
        }
            //cannot do this because GpsDirectory does not know about
            //GPS_DATE_STAMP
            //if(gps.containsTag(GpsDirectory.TAG_GPS_TIME_STAMP) &&
View Full Code Here

TOP

Related Classes of net.sourceforge.gpstools.gpx.Wpt

Copyright © 2018 www.massapicom. 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.