User:Xoff

From OpenStreetMap Wiki
Jump to navigation Jump to search
Babel user information
de-N Dieser Benutzer spricht Deutsch als Muttersprache.
en-3 This user has advanced knowledge of English.
Users by language

Public-images-osm logo.svg
I support OSM by being a
member of the
OpenStreetMap Foundation
Are you?

I support the license
upgrade to ODbL v 1.0

ODbL-Supporter.png


I discovered OpenStreetMap in 2008 and bought my first gps device soon afterwards in March 2008 with the main intention to map for osm. Luckily, there are plenty of white spots right at my doorstep, which I now slowly try to fill.

Mapping

My mapping activity ist mostly concentrated on the south of Birmingham. So far, I have mapped the Bournville Village Estate and parts of Weoley Castle. I also have done some mapping around my parents' place in Kassel in Germany. I hope to do a bit more there over Christmas, since their part of the city still looks like being a separate very small village. Most of my mapping I do either by feet (I love running!) or by bike.

Miscellaneous

Anonymise Tracks

This is a small shell script to anonymise gpx tracks. It does the following things:

  • It removes trackpoints in a number of defined polygons (around your house, around your workplace, ...)
  • It changes all timestamps by a random time interval (one interval for all timestamps, of course).
  • It removes cmt, desc and name tags from trackpoints.
  • It removes waypoints and routes from the file.
  • It simplifies the route by discarding trackpoints which are in a straight line.

The script will create a directory called upload in which the output file is placed. The polygonal areas to exclude are defined directly in the file below. The script depends on xsltproc and gpsbabel.

#!/bin/bash

if [ $# -lt 2 ] ; then
    echo "Usage: $0 infile outfile [crop]"
    exit -1
fi

IF=$1
OF=$2

if [ $# -eq 3 ] ; then
    if [ $3 = crop ] ; then
        CROP=1
    else
        CROP=0
    fi
else
    CROP=0
fi


DIR=upload

TEMP_A=${DIR}/temp-a.gpx
TEMP_B=${DIR}/temp-b.gpx

# Create upload directory
if [ -e ${DIR} ] ; then
    if [ ! -d ${DIR} ] ; then
        echo "Upload directory name exists but it is not a directory"
        exit -1
    fi
else
    mkdir ${DIR}
fi

# Define polygon areas within which all trackpoints will be discarded:
# Note: Polygons must be closed lines! So, repeat the first point at the
# end of the list. More information about the polygons can be found here:
# http://www.gpsbabel.org/htmldoc-1.3.6/filter_polygon.html
#
# Area 1:
POLYGONS[0]=${DIR}/polygon1.arc
echo $'52.23  -0.3
52.34  -1.2
52.65  -0.3
52.23  -0.3
' > "${POLYGONS[0]}"
# Area 2:
POLYGONS[1]=${DIR}/polygon2.arc
echo $'34.45 45.3
52.34  -1.2
52.65  -0.3
34.45 45.3
' > "${POLYGONS[1]}"
# and more areas...

# Discard routes and waypoints:
gpsbabel \
    -i gpx -f "${IF}" \
    -x nuketypes,waypoints,routes \
    -o gpx -F "${TEMP_A}"

# Crop track:
if [ $CROP -eq 1 ] ; then
    for I in $( seq 0 $(( ${#POLYGONS[@]} - 1 )) ) ; do
        gpsbabel -i gpx -f ${TEMP_A} -x transform,wpt=trk,del -x polygon,file=${POLYGONS[$I]},exclude -x transform,trk=wpt,del -o gpx -F ${TEMP_B}
        mv ${TEMP_B} ${TEMP_A}
    done
fi

# Adjust timestamps by a random number of hours and simplify track by reducing
# the number of trackpoints:
gpsbabel \
    -i gpx -f ${TEMP_A} \
    -x track,move=-${RANDOM}h,title="TRACK" \
    -x simplify,error=0.0005K,crosstrack \
    -o gpx -F ${TEMP_B}
mv ${TEMP_B} ${TEMP_A}

# Define stylesheet to remove name, cmt and desc tags from trackpoints:
XSLT=${DIR}/clean-trkpt.xsl
echo $'<?xml version="1.0"?>
<xsl:stylesheet
    version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:gpx="http://www.topografix.com/GPX/1/0"
>
<xsl:output method="xml"/>
<xsl:template match="gpx:trkpt/gpx:name"/>
<xsl:template match="gpx:trkpt/gpx:cmt"/>
<xsl:template match="gpx:trkpt/gpx:desc"/>
<xsl:template match="gpx:gpx/gpx:time"/>
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>
</xsl:stylesheet>' > "${XSLT}"

xsltproc "${XSLT}" "${TEMP_A}" > "${DIR}/${OF}"

rm -f ${POLYGONS[@]} ${TEMP_A} ${TEMP_B} ${XSLT}