#!/bin/sh
# $Id: makespeed-1,v 1.1 2011/07/03 03:24:39 grog Exp $
# Convert Trapster Garmin CSV format files into a speedcam.txt file for iGo 8.
#
# This is based on various reports on the web, and significantly
# complicated by the difference in the data.  Trapster reports the
# following types of "speed camera":
#
#     Red light cameras
#     Speed cameras, with no indication whether fixed or mobile
#     Combined red light and speed cameras
#
# These are the only ones which correspond even vaguely to the iGo categories.  The remainder are:
#
#     Police "enforcement" points.
#     Road hazards.
#
# By contrast, from a forum post at
# http://www.gps-data-team.com/pda-gps-navigation/viewtopic.php?t=1591#3941,
# it seems that iGo knows the following types of "speed camera":
#
#     1 - fixed speed camera locations
#     2 - combined red light and speed cameras
#     3 - fixed red light camera locations
#     4 - section camera positions
#     5 - lasers, hand-held radars and other mobile speed camera locations
#     6 - railway crossing
#     7 - not constant mobile locations
#
# In addition, iGo reports speed limits and directions of the camera,
# which Trapster doesn't.  I've chosen an arbitary limit of 100 km/h.
# This shouldn't stop the camera being reported even if you're going
# more slowly.  The format is:
#
# X,Y,TYPE,SPEED,DIRTYPE,DIRECTION 
# Where:
#   X = longitude
#   Y = latitude
#   TYPE = type of speed camera (see above).
#   SPEED = speed limit in km/h
#   DIRTYPE = type of direction of the speedcam (0-all directions; 1-one direction; 2-both directions)
#   DIRECTION = direction in degrees (0-North; 90-East) 
#
# Combined cameras, type 2
awk -F , < trapster-combo-camera-speed-0.csv '{printf ("%s,%s,2,100,0,0\n", $1, $2); }'
# Police "enforcement" points, type 5 (hand-held devices)
awk -F , < trapster-police-enforcement-point-speed-0.csv '{printf ("%s,%s,5,100,0,0\n", $1, $2); }'
# Red light cameras, type 3
awk -F , < trapster-redlight-camera-speed-0.csv '{printf ("%s,%s,3,100,0,0\n", $1, $2); }'
# Road hazards.  No idea what these are, but iGo doesn't know them.
# Report them as railway crossings, type 6
awk -F , < trapster-road-hazard-speed-0.csv '{printf ("%s,%s,6,100,0,0\n", $1, $2); }'
# Speed cameras.  Assume these are fixed, type 1.
awk -F , < trapster-speed-camera-speed-0.csv '{printf ("%s,%s,1,100,0,0\n", $1, $2); }'
