#!/usr/bin/perl # filename: makeroad.pl # author: Marvin Simkin # date: 2002-11-17 # purpose: read Garmin Mapsource output make road lines # syntax: makeroad.pl < tracklog > road.lin # tracklog: Garmin Mapsource ASCII trackpoint data # road.lin: Line draw instructions for tracks # NOTE: # Input data format: # ... other clutter ... # Trackpoint{t}N33.51644 W112.07347{t}1/27/01 2:33:06 PM{t}1230 ft{t} # Trackpoint{t}N33.51652 W112.07244{t}1/27/01 2:33:16 PM{t}1230 ft{t}{t}315 ft{t}00:00:10{t}21.5 mph{t}84° true # Trackpoint{t}N33.51652 W112.07073{t}1/27/01 2:33:27 PM{t}1230 ft{t}{t}523 ft{t}00:00:11{t}32.4 mph{t}90° true # Trackpoint{t}N33.51648 W112.06813{t}1/27/01 2:33:42 PM{t}1224 ft{t}{t}791 ft{t}00:00:15{t}35.9 mph{t}91° true # Trackpoint{t}N33.51644 W112.06549{t}1/27/01 2:33:58 PM{t}1219 ft{t}{t}804 ft{t}00:00:16{t}34.3 mph{t}91° true # Trackpoint{t}N33.51644 W112.06493{t}1/27/01 2:34:06 PM{t}1218 ft{t}{t}170 ft{t}00:00:08{t}14.5 mph{t}90° true # Trackpoint{t}N33.51644 W112.06493{t}1/27/01 2:34:16 PM{t}1216 ft{t}{t}0 ft{t}00:00:10{t}0.0 mph{t}0° true # Trackpoint{t}N33.51644 W112.06448{t}1/27/01 2:34:23 PM{t}1216 ft{t}{t}137 ft{t}00:00:07{t}13.4 mph{t}90° true # Trackpoint{t}N33.51644 W112.06350{t}1/27/01 2:34:30 PM{t}1216 ft{t}{t}301 ft{t}00:00:07{t}29.3 mph{t}90° true # Trackpoint{t}N33.51644 W112.06124{t}1/27/01 2:34:42 PM{t}1218 ft{t}{t}686 ft{t}00:00:12{t}39.0 mph{t}90° true # Output data format # color=r g b;line:X1,Y1,Z1,X2,Y2,Z2 # INITIALIZE: # This converts degrees to feet based on the following data points: # # DM-516 # GPS says N33.44793 W112.02730 # Data says 890346.0625 466326.40625 # # 004 # GPS says N33.45634 W112.00266 # Seems to be near map point for DM-501 # Data says 893605.5 473884.5 my $NSDegBase; $NSDegBase = 33.44793; my $NSFeetBase; $NSFeetBase = 890346.0625; my $EWDegBase; $EWDegBase= 112.00266; my $EWFeetBase; $EWFeetBase = 473884.5; my $NSFeetPerDeg; $NSFeetPerDeg = (893605.5 - $NSFeetBase) / (33.45634 - $NSDegBase); my $EWFeetPerDeg; $EWFeetPerDeg = (466326.40625 - $EWFeetBase) / (112.02730 - $EWDegBase); print STDERR "NSFeetPerDeg=$NSFeetPerDeg, EWFeetPerDeg=$EWFeetPerDeg\n"; ## TEST ##my $Test; ##while ($Test = <>) { ## my $N; ## my $W; ## ($N, $W) = split (' ', $Test); ## print "$N,$W\n"; ## $N = ($N - $NSDegBase) * $NSFeetPerDeg + $NSFeetBase; ## $W = ($W - $EWDegBase) * $EWFeetPerDeg + $EWFeetBase; ## print "$N,$W\n"; ##} ##exit; my $HiwayColor; $HiwayColor = '0.000 0.000 1.000'; my $StreetColor; $StreetColor = '0.000 1.000 0.000'; my @Column; my $LastNorth; $LastNorth = ''; my $LastWest; $LastWest = ''; my $LastHeight; $LastHeight = ''; # SUBROUTINES: use strict; # ARGUMENTS: # MAINLINE: my $Line; while ($Line = <>) { chomp $Line; @Column = split (' ', $Line); # don't bother with too-short lines if ($#Column > 5) { # interested in track name or trackpoints if ($Column[0] eq 'Track') { print STDERR "@Column[1..3]\n"; ##print "color=$HiwayColor\n"; print "color=$StreetColor\n"; $LastNorth = ''; $LastWest = ''; $LastHeight = ''; } elsif ($Column[0] eq 'Trackpoint') { # Trackpoint{t}N33.51644 W112.07347{t}1/27/01 2:33:06 PM{t}1230 ft{t} my $NorthDeg; $NorthDeg = $Column[1]; $NorthDeg =~ /^N([\.0-9]*)$/; $NorthDeg = $1; my $WestDeg; $WestDeg = $Column[2]; $WestDeg =~ /^W([\.0-9]*)$/; $WestDeg = $1; my $HeightFeet; $HeightFeet = $Column[6]; if ($NorthDeg and $WestDeg) { my $NorthFeet; my $WestFeet; $NorthFeet = ($NorthDeg - $NSDegBase) * $NSFeetPerDeg + $NSFeetBase; $WestFeet = ($WestDeg - $EWDegBase) * $EWFeetPerDeg + $EWFeetBase; # print STDERR "$NorthDeg,$WestDeg -> $NorthFeet,$WestFeet\n"; if ($LastNorth and $LastWest) { print "line:$LastWest,$LastNorth,$LastHeight,$WestFeet,$NorthFeet,$HeightFeet\n"; } $LastNorth = $NorthFeet; $LastWest = $WestFeet; $LastHeight = $HeightFeet; } else { print STDERR "Invalid Trackpoint: $Line\n"; } } } }