Results 1 to 3 of 3
  1. #1
    mtbr member
    Reputation:
    Join Date
    Mar 2005
    Posts
    993

    Utility for translating location (longitude/latitude/altitude)

    Is anyone aware of a utility that will translate trackpoints (likely in GPX format) by a set amount, i.e. add 10 meters to the elevation?

    I have a number of tracks that I'd like to merge. I'm assuming the accuracy of each individual track (and can mostly prove it), so would like to adjust each to a common point.

    I've found there are some Perl modules for reading/parsing/writing GPX data, so I could write my own, but I suspect I'd spend as much time figuring out how to get the modules installed on my Windows PC as I would coding up the transformation.

    Potentially I could also use GPSBabel to convert to CSV, import into Excel, transform, then reverse ... in lieu of something else, that might be the quickest.

  2. #2
    Two Tired
    Reputation: CheapWhine's Avatar
    Join Date
    Dec 2005
    Posts
    366
    Changing the elevation is pretty straight forward since there is a single field that is already specified in meters. Changing location is a by an offset is a bit trickier because it is measured in degrees and you will probably need to change both latitude and longitude to implement your offset.

    Since your elevation change is straightforward, a simple replacement should do the trick. Here is a bit of Perl code that seems to do the trick without using any special packages. I did some testing, but your mileage may vary.


    print "What is the name of the file you want to convert? ";
    my $file = <>;
    chomp $file;
    die("No input file $file") if (! -f $file);
    print "What vertical offset to you want to add? ";
    my $offset = <>;
    chomp $offset;

    my $out = "new_$file";
    open IN, "<$file" or die "Can't open input file $file";
    open OUT, ">$out" or die "Can't open output file $out";
    while (my $line = ) {
    while ((my $loc = index($line,"<\/ele>")) >= 0) {
    my $s = substr($line,0,$loc+6);
    $line = substr($line,$loc+6);
    $s =~ s/ *([0-9.-]+) *<\/ele>//;
    $s .= $1 + $offset . "<\/ele>";
    print OUT $s;
    }
    print OUT $line;
    }
    close IN;
    close OUT;
    print "Updated file is $out\n";
    Let the good times roll.
    trailroller.com

  3. #3
    mtbr member
    Reputation:
    Join Date
    Mar 2005
    Posts
    993
    Thanks for the snippet.

    You're right, it is reasonably straightforward ... I was blinded by have multiple tracks in one .gpx and thinking I needed to parse the XML. I'll take your code and add a simple search for the first instance of the track name and then the close of the track.


    Quote Originally Posted by CheapWhine
    Changing the elevation is pretty straight forward since there is a single field that is already specified in meters. Changing location is a by an offset is a bit trickier because it is measured in degrees and you will probably need to change both latitude and longitude to implement your offset.

    Since your elevation change is straightforward, a simple replacement should do the trick. Here is a bit of Perl code that seems to do the trick without using any special packages. I did some testing, but your mileage may vary.


    print "What is the name of the file you want to convert? ";
    my $file = <>;
    chomp $file;
    die("No input file $file") if (! -f $file);
    print "What vertical offset to you want to add? ";
    my $offset = <>;
    chomp $offset;

    my $out = "new_$file";
    open IN, "<$file" or die "Can't open input file $file";
    open OUT, ">$out" or die "Can't open output file $out";
    while (my $line = ) {
    while ((my $loc = index($line,"<\/ele>")) >= 0) {
    my $s = substr($line,0,$loc+6);
    $line = substr($line,$loc+6);
    $s =~ s/ *([0-9.-]+) *<\/ele>//;
    $s .= $1 + $offset . "<\/ele>";
    print OUT $s;
    }
    print OUT $line;
    }
    close IN;
    close OUT;
    print "Updated file is $out\n";

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •