"You veered off the course" warning ?

Started by Testi, February 09, 2014, 12:22:05

0 Members and 1 Guest are viewing this topic.


Geez, I didn't mean to imply any fault on Locus' part or to start a fight!

My tracks don't have many points because it's planned routes I click together in Google Earth, but I'm sure I can find a way to make it generate intermediate points. Lots of sun in the forecast for Sunday, so I'll find out then!


Don't worry, fights do not exists on Locus forum ;)

To plan track, I may suggest to use Add new route & measure function. It offer quite useful tool under button 5. Just keep in mind, that this function require internet connection
- Official help (ideas, questions, problems): help.locusmap.eu
- Advanced topics, sharing of knowledges: you're here!
- LM 4 Beta download, LM 4 Release download


I have a powerful desktop computer and a gigantic monitor, so at home I tend to not use my phone for anything, but I will try a few different ways to do it tomorrow.


Here are my results from some experimenting:

I can't use the navigation function, because I plan hiking trips on dirt trails and such that are not navigable, and even if they were, I just want to pick routes on the maps, not generate routes. When drawing with Locus, it also doesn't make intermediate points on its own.

So I wrote a short little Java program to take a .KML file and just add points in the middle of long lines. Maybe someone else might want something like that, so here goes:

package com.boringville.misc.pointadder;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;

import lombok.RequiredArgsConstructor;
import de.micromata.opengis.kml.v_2_2_0.Coordinate;
import de.micromata.opengis.kml.v_2_2_0.Document;
import de.micromata.opengis.kml.v_2_2_0.Feature;
import de.micromata.opengis.kml.v_2_2_0.Kml;
import de.micromata.opengis.kml.v_2_2_0.LineString;
import de.micromata.opengis.kml.v_2_2_0.Placemark;

public class PointAdder {
    private static class Distance {
        private final Coordinate first, last;

        /** Basically copied from http://stackoverflow.com/questions/837872 */
        public double calculate() {
            double dLat = Math.toRadians(last.getLatitude() - first.getLatitude());
            double dLng = Math.toRadians(last.getLongitude() - first.getLongitude());
            double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
                    + Math.cos(Math.toRadians(first.getLatitude()))
                    * Math.cos(Math.toRadians(last.getLatitude())) * Math.sin(dLng / 2)
                    * Math.sin(dLng / 2);
            double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
            return c;

    public static void main(String[] args) {
        double earthRadius = 6369628.75D;
        double maxDistance = Double.parseDouble(args[0]) / earthRadius;
        Kml kml = Kml.unmarshal(new File(args[1]));
        Document document = (Document) kml.getFeature();
        for (Feature feature : document.getFeature()) {
            if (!(feature instanceof Placemark)) {
            Placemark placemark = (Placemark) feature;
            LineString ls = (LineString) placemark.getGeometry();
            List<Coordinate> inCoords = ls.getCoordinates();
            List<Coordinate> outCoords = new ArrayList<Coordinate>();
            Coordinate lastPoint = null;
            for (Coordinate coordinate : inCoords) {
                if (lastPoint != null) {
                    double distance = new Distance(lastPoint, coordinate).calculate();

                    if (distance > maxDistance) {
                        double steps = Math.ceil(distance / maxDistance);
                        double stepLong = (coordinate.getLongitude() - lastPoint.getLongitude())
                                / steps;
                        double stepLat = (coordinate.getLatitude() - lastPoint.getLatitude())
                                / steps;
                        for (int i = 0; i < steps; i++) {
                            outCoords.add(new Coordinate(lastPoint.getLongitude() + stepLong * i,
                                    lastPoint.getLatitude() + stepLat * i));
                lastPoint = coordinate;
        try {
            kml.marshal(new File(args[2]));
        } catch (final FileNotFoundException e) {

And here is the neccessary pom.xml if you want to build it without fiddling with class paths and libraries:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">





I don't really understand licenses but everyone is free to do whatever they want with the code as long as they don't try to hold me accountable for blowing up their computers ;)

Ooops almost forgot, you use it by doing "java PointAdder 50 in.kml out.kml" where in.kml is the Google Earth or whatever generated one and out.kml is the name of the resulting file. 50 is the maximum distance in meters that you want between two points.


Here you can see what it does, before:

As you can see, I only put a point at the start of Rotsiefweg and at the end, since it's very straight. But it's 500m long, so at my setting to beep if you get more than 100m from the track, it would beep in between.

Here's the 'after':