Mountain Bike Reviews Forum banner
1 - 3 of 3 Posts

·
Registered
Joined
·
1,085 Posts
Discussion Starter · #1 ·
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.
 

·
Two Tired
Joined
·
397 Posts
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 = <IN>) {
while ((my $loc = index($line,"<\/ele>")) >= 0) {
my $s = substr($line,0,$loc+6);
$line = substr($line,$loc+6);
$s =~ s/<ele> *([0-9.-]+) *<\/ele>/<ele>/;
$s .= $1 + $offset . "<\/ele>";
print OUT $s;
}
print OUT $line;
}
close IN;
close OUT;
print "Updated file is $out\n";
 

·
Registered
Joined
·
1,085 Posts
Discussion Starter · #3 ·
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.

CheapWhine said:
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 = <IN>) {
while ((my $loc = index($line,"<\/ele>")) >= 0) {
my $s = substr($line,0,$loc+6);
$line = substr($line,$loc+6);
$s =~ s/<ele> *([0-9.-]+) *<\/ele>/<ele>/;
$s .= $1 + $offset . "<\/ele>";
print OUT $s;
}
print OUT $line;
}
close IN;
close OUT;
print "Updated file is $out\n";
 
1 - 3 of 3 Posts
This is an older thread, you may not receive a response, and could be reviving an old thread. Please consider creating a new thread.
Top