Package org.openstreetmap.josm.data.gpx

Examples of org.openstreetmap.josm.data.gpx.WayPoint


        Collection<WayPoint> waypoints = new ArrayList<>();
        boolean timedMarkersOmitted = false;
        boolean untimedMarkersOmitted = false;
        double snapDistance = Main.pref.getDouble("marker.audiofromuntimedwaypoints.distance", 1.0e-3);
        // about 25 m
        WayPoint wayPointFromTimeStamp = null;

        // determine time of first point in track
        double firstTime = -1.0;
        if (hasTracks) {
            for (GpxTrack track : layer.data.tracks) {
                for (GpxTrackSegment seg : track.getSegments()) {
                    for (WayPoint w : seg.getWayPoints()) {
                        firstTime = w.time;
                        break;
                    }
                    if (firstTime >= 0.0) {
                        break;
                    }
                }
                if (firstTime >= 0.0) {
                    break;
                }
            }
        }
        if (firstTime < 0.0) {
            JOptionPane.showMessageDialog(
                    Main.parent,
                    tr("No GPX track available in layer to associate audio with."),
                    tr("Error"),
                    JOptionPane.ERROR_MESSAGE
                    );
            return;
        }

        // (a) try explicit timestamped waypoints - unless suppressed
        if (Main.pref.getBoolean("marker.audiofromexplicitwaypoints", true) && hasWaypoints) {
            for (WayPoint w : layer.data.waypoints) {
                if (w.time > firstTime) {
                    waypoints.add(w);
                } else if (w.time > 0.0) {
                    timedMarkersOmitted = true;
                }
            }
        }

        // (b) try explicit waypoints without timestamps - unless suppressed
        if (Main.pref.getBoolean("marker.audiofromuntimedwaypoints", true) && hasWaypoints) {
            for (WayPoint w : layer.data.waypoints) {
                if (waypoints.contains(w)) {
                    continue;
                }
                WayPoint wNear = layer.data.nearestPointOnTrack(w.getEastNorth(), snapDistance);
                if (wNear != null) {
                    WayPoint wc = new WayPoint(w.getCoor());
                    wc.time = wNear.time;
                    if (w.attr.containsKey("name")) {
                        wc.attr.put("name", w.getString("name"));
                    }
                    waypoints.add(wc);
                } else {
                    untimedMarkersOmitted = true;
                }
            }
        }

        // (c) use explicitly named track points, again unless suppressed
        if ((Main.pref.getBoolean("marker.audiofromnamedtrackpoints", false)) && layer.data.tracks != null
                && !layer.data.tracks.isEmpty()) {
            for (GpxTrack track : layer.data.tracks) {
                for (GpxTrackSegment seg : track.getSegments()) {
                    for (WayPoint w : seg.getWayPoints()) {
                        if (w.attr.containsKey("name") || w.attr.containsKey("desc")) {
                            waypoints.add(w);
                        }
                    }
                }
            }
        }

        // (d) use timestamp of file as location on track
        if ((Main.pref.getBoolean("marker.audiofromwavtimestamps", false)) && hasTracks) {
            double lastModified = wavFile.lastModified() / 1000.0; // lastModified is in
            // milliseconds
            double duration = AudioUtil.getCalibratedDuration(wavFile);
            double startTime = lastModified - duration;
            startTime = firstStartTime + (startTime - firstStartTime)
                    / Main.pref.getDouble("audio.calibration", 1.0 /* default, ratio */);
            WayPoint w1 = null;
            WayPoint w2 = null;

            for (GpxTrack track : layer.data.tracks) {
                for (GpxTrackSegment seg : track.getSegments()) {
                    for (WayPoint w : seg.getWayPoints()) {
                        if (startTime < w.time) {
                            w2 = w;
                            break;
                        }
                        w1 = w;
                    }
                    if (w2 != null) {
                        break;
                    }
                }
            }

            if (w1 == null || w2 == null) {
                timedMarkersOmitted = true;
            } else {
                wayPointFromTimeStamp = new WayPoint(w1.getCoor().interpolate(w2.getCoor(),
                        (startTime - w1.time) / (w2.time - w1.time)));
                wayPointFromTimeStamp.time = startTime;
                String name = wavFile.getName();
                int dot = name.lastIndexOf('.');
                if (dot > 0) {
                    name = name.substring(0, dot);
                }
                wayPointFromTimeStamp.attr.put("name", name);
                waypoints.add(wayPointFromTimeStamp);
            }
        }

        // (e) analyse audio for spoken markers here, in due course

        // (f) simply add a single marker at the start of the track
        if ((Main.pref.getBoolean("marker.audiofromstart") || waypoints.isEmpty()) && hasTracks) {
            boolean gotOne = false;
            for (GpxTrack track : layer.data.tracks) {
                for (GpxTrackSegment seg : track.getSegments()) {
                    for (WayPoint w : seg.getWayPoints()) {
                        WayPoint wStart = new WayPoint(w.getCoor());
                        wStart.attr.put("name", "start");
                        wStart.time = w.time;
                        waypoints.add(wStart);
                        gotOne = true;
                        break;
View Full Code Here


            }
            // now for the content
            String[] e = chkstrings[0].split(",");
            String accu;

            WayPoint currentwp = ps.p_Wp;
            String currentDate = ps.p_Date;

            // handle the packet content
            if("$GPGGA".equals(e[0]) || "$GNGGA".equals(e[0])) {
                // Position
                LatLon latLon = parseLatLon(
                        e[GPGGA.LATITUDE_NAME.position],
                        e[GPGGA.LONGITUDE_NAME.position],
                        e[GPGGA.LATITUDE.position],
                        e[GPGGA.LONGITUDE.position]
                );
                if (latLon==null) {
                    throw new IllegalDataException("Malformed lat/lon");
                }

                if ((latLon.lat()==0.0) && (latLon.lon()==0.0)) {
                    ps.zero_coord++;
                    return false;
                }

                // time
                accu = e[GPGGA.TIME.position];
                Date d = readTime(currentDate+accu);

                if((ps.p_Time==null) || (currentwp==null) || !ps.p_Time.equals(accu)) {
                    // this node is newer than the previous, create a new waypoint.
                    // no matter if previous WayPoint was null, we got something
                    // better now.
                    ps.p_Time=accu;
                    currentwp = new WayPoint(latLon);
                }
                if(!currentwp.attr.containsKey("time")) {
                    // As this sentence has no complete time only use it
                    // if there is no time so far
                    currentwp.attr.put("time", DateUtils.fromDate(d));
                }
                // elevation
                accu=e[GPGGA.HEIGHT_UNTIS.position];
                if("M".equals(accu)) {
                    // Ignore heights that are not in meters for now
                    accu=e[GPGGA.HEIGHT.position];
                    if(!accu.isEmpty()) {
                        Double.parseDouble(accu);
                        // if it throws it's malformed; this should only happen if the
                        // device sends nonstandard data.
                        if(!accu.isEmpty()) { // FIX ? same check
                            currentwp.attr.put("ele", accu);
                        }
                    }
                }
                // number of sattelites
                accu=e[GPGGA.SATELLITE_COUNT.position];
                int sat = 0;
                if(!accu.isEmpty()) {
                    sat = Integer.parseInt(accu);
                    currentwp.attr.put("sat", accu);
                }
                // h-dilution
                accu=e[GPGGA.HDOP.position];
                if(!accu.isEmpty()) {
                    currentwp.attr.put("hdop", Float.parseFloat(accu));
                }
                // fix
                accu=e[GPGGA.QUALITY.position];
                if(!accu.isEmpty()) {
                    int fixtype = Integer.parseInt(accu);
                    switch(fixtype) {
                    case 0:
                        currentwp.attr.put("fix", "none");
                        break;
                    case 1:
                        if(sat < 4) {
                            currentwp.attr.put("fix", "2d");
                        } else {
                            currentwp.attr.put("fix", "3d");
                        }
                        break;
                    case 2:
                        currentwp.attr.put("fix", "dgps");
                        break;
                    default:
                        break;
                    }
                }
            } else if("$GPVTG".equals(e[0]) || "$GNVTG".equals(e[0])) {
                // COURSE
                accu = e[GPVTG.COURSE_REF.position];
                if("T".equals(accu)) {
                    // other values than (T)rue are ignored
                    accu = e[GPVTG.COURSE.position];
                    if(!accu.isEmpty()) {
                        Double.parseDouble(accu);
                        currentwp.attr.put("course", accu);
                    }
                }
                // SPEED
                accu = e[GPVTG.SPEED_KMH_UNIT.position];
                if(accu.startsWith("K")) {
                    accu = e[GPVTG.SPEED_KMH.position];
                    if(!accu.isEmpty()) {
                        double speed = Double.parseDouble(accu);
                        speed /= 3.6; // speed in m/s
                        currentwp.attr.put("speed", Double.toString(speed));
                    }
                }
            } else if("$GPGSA".equals(e[0]) || "$GNGSA".equals(e[0])) {
                // vdop
                accu=e[GPGSA.VDOP.position];
                if(!accu.isEmpty()) {
                    currentwp.attr.put("vdop", Float.parseFloat(accu));
                }
                // hdop
                accu=e[GPGSA.HDOP.position];
                if(!accu.isEmpty()) {
                    currentwp.attr.put("hdop", Float.parseFloat(accu));
                }
                // pdop
                accu=e[GPGSA.PDOP.position];
                if(!accu.isEmpty()) {
                    currentwp.attr.put("pdop", Float.parseFloat(accu));
                }
            }
            else if("$GPRMC".equals(e[0]) || "$GNRMC".equals(e[0])) {
                // coordinates
                LatLon latLon = parseLatLon(
                        e[GPRMC.WIDTH_NORTH_NAME.position],
                        e[GPRMC.LENGTH_EAST_NAME.position],
                        e[GPRMC.WIDTH_NORTH.position],
                        e[GPRMC.LENGTH_EAST.position]
                );
                if((latLon.lat()==0.0) && (latLon.lon()==0.0)) {
                    ps.zero_coord++;
                    return false;
                }
                // time
                currentDate = e[GPRMC.DATE.position];
                String time = e[GPRMC.TIME.position];

                Date d = readTime(currentDate+time);

                if((ps.p_Time==null) || (currentwp==null) || !ps.p_Time.equals(time)) {
                    // this node is newer than the previous, create a new waypoint.
                    ps.p_Time=time;
                    currentwp = new WayPoint(latLon);
                }
                // time: this sentence has complete time so always use it.
                currentwp.attr.put("time", DateUtils.fromDate(d));
                // speed
                accu = e[GPRMC.SPEED.position];
View Full Code Here

                    currentState = State.metadata;
                    break;
                case "wpt":
                    states.push(currentState);
                    currentState = State.wpt;
                    currentWayPoint = new WayPoint(parseLatLon(atts));
                    break;
                case "rte":
                    states.push(currentState);
                    currentState = State.rte;
                    currentRoute = new GpxRoute();
                    break;
                case "trk":
                    states.push(currentState);
                    currentState = State.trk;
                    currentTrack = new ArrayList<>();
                    currentTrackAttr = new HashMap<>();
                    break;
                case "extensions":
                    states.push(currentState);
                    currentState = State.ext;
                    currentExtensions = new Extensions();
                    break;
                case "gpx":
                    if (atts.getValue("creator") != null && atts.getValue("creator").startsWith("Nokia Sports Tracker")) {
                        nokiaSportsTrackerBug = true;
                    }
                }
                break;
            case metadata:
                switch (localName) {
                case "author":
                    states.push(currentState);
                    currentState = State.author;
                    break;
                case "extensions":
                    states.push(currentState);
                    currentState = State.ext;
                    currentExtensions = new Extensions();
                    break;
                case "copyright":
                    states.push(currentState);
                    currentState = State.copyright;
                    data.attr.put(META_COPYRIGHT_AUTHOR, atts.getValue("author"));
                    break;
                case "link":
                    states.push(currentState);
                    currentState = State.link;
                    currentLink = new GpxLink(atts.getValue("href"));
                }
                break;
            case author:
                switch (localName) {
                case "link":
                    states.push(currentState);
                    currentState = State.link;
                    currentLink = new GpxLink(atts.getValue("href"));
                    break;
                case "email":
                    data.attr.put(META_AUTHOR_EMAIL, atts.getValue("id") + "@" + atts.getValue("domain"));
                }
                break;
            case trk:
                switch (localName) {
                case "trkseg":
                    states.push(currentState);
                    currentState = State.trkseg;
                    currentTrackSeg = new ArrayList<>();
                    break;
                case "link":
                    states.push(currentState);
                    currentState = State.link;
                    currentLink = new GpxLink(atts.getValue("href"));
                    break;
                case "extensions":
                    states.push(currentState);
                    currentState = State.ext;
                    currentExtensions = new Extensions();
                }
                break;
            case trkseg:
                if ("trkpt".equals(localName)) {
                    states.push(currentState);
                    currentState = State.wpt;
                    currentWayPoint = new WayPoint(parseLatLon(atts));
                }
                break;
            case wpt:
                switch (localName) {
                case "link":
                    states.push(currentState);
                    currentState = State.link;
                    currentLink = new GpxLink(atts.getValue("href"));
                    break;
                case "extensions":
                    states.push(currentState);
                    currentState = State.ext;
                    currentExtensions = new Extensions();
                    break;
                }
                break;
            case rte:
                switch (localName) {
                case "link":
                    states.push(currentState);
                    currentState = State.link;
                    currentLink = new GpxLink(atts.getValue("href"));
                    break;
                case "rtept":
                    states.push(currentState);
                    currentState = State.wpt;
                    currentWayPoint = new WayPoint(parseLatLon(atts));
                    break;
                case "extensions":
                    states.push(currentState);
                    currentState = State.ext;
                    currentExtensions = new Extensions();
View Full Code Here

     * Override in subclasses to add all necessary attributes.
     *
     * @return the corresponding WayPoint with all relevant attributes
     */
    public WayPoint convertToWayPoint() {
        WayPoint wpt = new WayPoint(getCoor());
        wpt.put("time", timeFormatter.format(new Date(Math.round(time * 1000))));
        if (text != null) {
            wpt.addExtension("text", text);
        } else if (dataProvider != null) {
            for (String key : dataProvider.getTemplateKeys()) {
                Object value = dataProvider.getTemplateValue(key, false);
                if (value != null && GpxConstants.WPT_KEYS.contains(key)) {
                    wpt.put(key, value);
                }
            }
        }
        return wpt;
    }
View Full Code Here

        }
    }

    @Override
    public WayPoint convertToWayPoint() {
        WayPoint wpt = super.convertToWayPoint();
        GpxLink link = new GpxLink(webUrl.toString());
        link.type = "web";
        wpt.attr.put(GpxConstants.META_LINKS, Collections.singleton(link));
        return wpt;
    }
View Full Code Here

     * providing we are within reasonable distance from the track; otherwise reset to the
     * original position.
     * @param en the position to start looking from
     */
    public void reposition(EastNorth en) {
        WayPoint cw = null;
        AudioMarker recent = AudioMarker.recentlyPlayedMarker();
        if (recent != null && recent.parentLayer != null && recent.parentLayer.fromLayer != null) {
            /* work out EastNorth equivalent of 50 (default) pixels tolerance */
            Point p = Main.map.mapView.getPoint(en);
            EastNorth enPlus25px = Main.map.mapView.getEastNorth(p.x+dropTolerance, p.y);
            cw = recent.parentLayer.fromLayer.data.nearestPointOnTrack(en, enPlus25px.east() - en.east());
        }

        AudioMarker ca = null;
        /* Find the prior audio marker (there should always be one in the
         * layer, even if it is only one at the start of the track) to
         * offset the audio from */
        if (cw != null && recent != null && recent.parentLayer != null) {
            for (Marker m : recent.parentLayer.data) {
                if (m instanceof AudioMarker) {
                    AudioMarker a = (AudioMarker) m;
                    if (a.time > cw.time) {
                        break;
                    }
                    ca = a;
                }
            }
        }

        if (ca == null) {
            /* Not close enough to track, or no audio marker found for some other reason */
            JOptionPane.showMessageDialog(
                    Main.parent,
                    tr("You need to drag the play head near to the GPX track whose associated sound track you were playing (after the first marker)."),
                    tr("Warning"),
                    JOptionPane.WARNING_MESSAGE
                    );
            endDrag(true);
        } else {
            setCoor(cw.getCoor());
            ca.play(cw.time - ca.time);
            endDrag(false);
        }
    }
View Full Code Here

        /* If we didn't hit an audio marker, we need to create one at the nearest point on the track */
        if (ca == null) {
            /* work out EastNorth equivalent of 50 (default) pixels tolerance */
            Point p = Main.map.mapView.getPoint(en);
            EastNorth enPlus25px = Main.map.mapView.getEastNorth(p.x+dropTolerance, p.y);
            WayPoint cw = recent.parentLayer.fromLayer.data.nearestPointOnTrack(en, enPlus25px.east() - en.east());
            if (cw == null) {
                JOptionPane.showMessageDialog(
                        Main.parent,
                        tr("You need to SHIFT-drag the play head onto an audio marker or onto the track point where you want to synchronize."),
                        tr("Warning"),
                        JOptionPane.WARNING_MESSAGE
                        );
                endDrag(true);
                return;
            }
            ca = recent.parentLayer.addAudioMarker(cw.time, cw.getCoor());
        }

        /* Actually do the synchronization */
        if(ca == null) {
            JOptionPane.showMessageDialog(
View Full Code Here

        if (trackLayer == null)
            return;
        /* find the pair of track points for this position (adjusted by the syncOffset)
         * and interpolate between them
         */
        WayPoint w1 = null;
        WayPoint w2 = null;

        for (GpxTrack track : trackLayer.data.tracks) {
            for (GpxTrackSegment trackseg : track.getSegments()) {
                for (WayPoint w: trackseg.getWayPoints()) {
                    if (audioTime < w.time) {
                        w2 = w;
                        break;
                    }
                    w1 = w;
                }
                if (w2 != null) {
                    break;
                }
            }
            if (w2 != null) {
                break;
            }
        }

        if (w1 == null)
            return;
        setEastNorth(w2 == null ?
                w1.getEastNorth() :
                    w1.getEastNorth().interpolate(w2.getEastNorth(),
                            (audioTime - w1.time)/(w2.time - w1.time)));
        time = audioTime;
        if (jumpToMarker) {
            jumpToMarker = false;
            Main.map.mapView.zoomTo(w1.getEastNorth());
View Full Code Here

        return new ImageIcon(img.getScaledInstance(w, h, Image.SCALE_SMOOTH));
    }

    @Override
    public WayPoint convertToWayPoint() {
        WayPoint wpt = super.convertToWayPoint();
        GpxLink link = new GpxLink(imageUrl.toString());
        link.type = "image";
        wpt.attr.put(GpxConstants.META_LINKS, Collections.singleton(link));
        return wpt;
    }
View Full Code Here

        return TemplateEntryProperty.forAudioMarker(parentLayer.getName());
    }

    @Override
    public WayPoint convertToWayPoint() {
        WayPoint wpt = super.convertToWayPoint();
        GpxLink link = new GpxLink(audioUrl.toString());
        link.type = "audio";
        wpt.attr.put(GpxConstants.META_LINKS, Collections.singleton(link));
        wpt.addExtension("offset", Double.toString(offset));
        wpt.addExtension("sync-offset", Double.toString(syncOffset));
        return wpt;
    }
View Full Code Here

TOP

Related Classes of org.openstreetmap.josm.data.gpx.WayPoint

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.