#!/usr/local/bin/perl # ----------------------------------------------------------------- # # 'csv2pgx.pl' # # Convert a comma-delimited list of waypoints to GPX format. # # This script is extremely basic; the resulting GPX file is NOT complete. # I use this mosty to add geographic locations to (other) GPX files. # # ----------------------------------------------------------------- # This program is free software; you can redistribute it and/or # modify it under the terms of the version 2 of the GNU General # Public License as published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # ----------------------------------------------------------------- # # Copyright (c) 2007 Joerg Hau . # # Revision History: # 2007-05-21, JHa, first working version, # ----------------------------------------------------------------- use strict; use warnings; # input file is: # latitude,longitude,name ... e.g.: # 50.056386,6.028103,Clervaux # # output is: # # Clervaux # Clervaux # Clervaux # Small City # my $template=" NAME TXT TXT Small City \n"; # ----------------------------------------------------------------- # Print usage mode # ----------------------------------------------------------------- sub usage { print <. This program is free software; you can redistribute it and-or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. Usage: $0 listfile EOF } # ----------------------------------------------------------------- # testing # ----------------------------------------------------------------- my $numArgs = $#ARGV + 1; unless ($numArgs==1) { usage; die "Error: Please provide input filename.\n" } # ----------------------------------------------------------------- # read file # ----------------------------------------------------------------- my ($infile) = @ARGV; if (! -r $infile) { die "Can't read input $infile\n"; } if (! -f $infile) { die "Input $infile is not a plain file\n"; } open (FILE, $infile) or die ("Could not open '$infile'!"); my ($lon,$lat,$name); while () { chop $_; ($lat,$lon,$name) = split ',', $_; #print "$lat : $lon : $name\n"; my $temp = $template; $temp =~ s/LAT/$lat/g; $temp =~ s/LON/$lon/g; $temp =~ s/TXT/$name/g; $name =~ tr/a-z/A-Z/; # uppercase $temp =~ s/NAME/$name/g; print $temp; } close (FILE); 1;