OpenStreetMap-logo OpenStreetMap

I wrote a little shell script that processes various gpsbabel filters on gpx files, perhaps it is usefull for somewone else.

The following filters will be used:
- remove any trackpoints in the neighbourhood of your home (for privacy, do not forget to enter your position, lat= and lon=) (if you want to filter more regions you can duplicate the radius,distance line)
- remove any trackpoints that have a distance < 2 meters
- remove duplicate trackpoints
- simplify the track (removes unnecessary trackpoints)
- remove trackpoints with a hdop > 4

Here is the script:

#!/bin/sh
if [ -z "$1" -o -z "$2" ]; then
echo "usage: $0 infile outfile"
exit 1
fi

tmpfile=$(mktemp)

gpsbabel -i gpx -f "$1" \
-x transform,wpt=trk,del \
-x radius,distance=0.8K,lat=48,lon=11,nosort,exclude \
-x transform,trk=wpt,del \
-x duplicate,location \
-x position,distance=2m \
-x simplify,crosstrack,error=0.001k \
-x discard,hdop=4 \
-o gpx -F "$tmpfile"

# removes some crap gpsbabel added to the file
sed '/^.*<name>.*$/d' "$tmpfile" | sed '/^.*<cmt>.*$/d' | sed '/^.*<desc>.*$/d' > $2

rm $tmpfile

Email icon Bluesky Icon Facebook Icon LinkedIn Icon Mastodon Icon Telegram Icon X Icon

Discussion

Reäksje fan M526244 op 22 april 2011 om 22.34 oere

Hello. Thank you for sharing this script. However, doesn't the sed pipe near the
end effectively delete all lines?

If not, would this be simpler?

sed '/^.*$/d "tmpfile" >$2

Also a warning: the mktemp command is creating temporay files which are not
being cleaned up. Maybe the three uses of "tmpfile" ought to be $tmpfile
instead?

Reäksje fan BitSchupser op 22 april 2011 om 23.24 oere

Hi,
thanks for your comment.

The sed pipe was not correctly displayed because this blog software does not transform to HTML entities automatically -- I corrected it.

With the variable $tmpfile you where right, I also corrected it. I am wondering why it worked without the $ sign?

You're right that the mktemp command does not clean up automatically but therefor I do a rm at the end of the script.

Meld jo oan en lit in reäksje efter