/[maps]/bin/nmea2kml.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /bin/nmea2kml.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 20 by dpavlin, Mon Dec 3 20:52:33 2007 UTC revision 21 by dpavlin, Mon Dec 3 21:37:25 2007 UTC
# Line 5  Line 5 
5  use strict;  use strict;
6  use warnings;  use warnings;
7    
8    use Getopt::Long;
9    
10    my $placemarks = 1;
11    my $line = 1;
12    
13    GetOptions(
14            'placemarks!' => \$placemarks,
15            'line!' => \$line,
16    );
17    
18  use lib '../';  use lib '../';
19  use NMEA;  use NMEA;
20    
21  my $path = shift @ARGV || die "usage: $0 nmea_dump.gps\n";  my $path = shift @ARGV || die "usage: $0 nmea_dump.gps\n";
22    
 my $individual_placemarks = 0;  
   
23  open(my $fh, '<', $path) || die "can't open $path: $!";  open(my $fh, '<', $path) || die "can't open $path: $!";
24    
25  my $out_path = $path;  my $out_path = $path;
26  $out_path =~ s!^.*?([^/]+)\.[^/]+$!$1!; #!  $out_path =~ s!^.*?([^/]+)$!$1!;        #!
27  $out_path .= '.kml';  $out_path .= '.kml';
28    
29  open(my $out, '>', $out_path) || die "can't open $out_path: $!";  open(my $out, '>', $out_path) || die "can't open $out_path: $!";
# Line 30  print $out qq{<?xml version="1.0" encodi Line 38  print $out qq{<?xml version="1.0" encodi
38    
39  print $out qq{  print $out qq{
40                  <Placemark id='linestring1'>                  <Placemark id='linestring1'>
41                          <name>$path</name>                          <name>Line</name>
42                          <LineString>                          <LineString>
43                          <extrude>1</extrude>                          <extrude>1</extrude>
44                          <altitudeMode>relativeToGround</altitudeMode>                          <altitudeMode>relativeToGround</altitudeMode>
45                          <coordinates>                          <coordinates>
46  } unless $individual_placemarks;  } if $line;
47    
48  my $point = 0;  my $point = 0;
49    my @placemarks;
50    
51  while(<$fh>) {  while(<$fh>) {
52          my $hash = NMEA->line( $_ ) || next;          my $hash = NMEA->line( $_ ) || next;
53    
54          $point++;          $point++;
55    
56          if ( $individual_placemarks ) {          if ( $placemarks ) {
57                    push @placemarks, qq{
                 print $out qq{  
58                  <Placemark>                  <Placemark>
59                          <name>$point</name>                          <name>$point</name>
60                          <description>                          <description>
61                  }, join(' ', map { ucfirst($_) . ':' . $hash->{$_} } ( qw/time lat lon speed course date var var_ew/ ) ), qq{                  }, join(' ', map { ucfirst($_) . ':' . $hash->{$_} } ( qw/time lat lon speed course date var var_ew/ ) ), qq{
62                          </description>                          </description>
63                          <Point>                          <Point>
64                                  <coordinates>}, $hash->{lon}, ',', $hash->{lat}, qq{,0</coordinates>                                  <coordinates>}, join(',', $hash->{lon}, $hash->{lat}, 0), qq{</coordinates>
65                          </Point>                          </Point>
66                  </Placemark>                  </Placemark>
67                  };                  };
   
         } else {  
                 print $out $hash->{lon}, ',', $hash->{lat}, 0, "\n";  
68          }          }
69    
70            print $out join(',', $hash->{lon}, $hash->{lat}, 0), "\n" if $line;
71  }  }
72    
73  print $out qq{  print $out qq{
74                          </coordinates>                          </coordinates>
75                          </LineString>                          </LineString>
76                  </Placemark>                  </Placemark>
77  } unless $individual_placemarks;  } if $line;
78    
79    if ( $placemarks ) {
80            print $out qq{
81            </Folder>
82            <Folder>
83                    <name>Placemarks</name>
84            }, join("\n", @placemarks), qq{
85            };
86    }
87    
88  print $out qq{  print $out qq{
89          </Folder>          </Folder>

Legend:
Removed from v.20  
changed lines
  Added in v.21

  ViewVC Help
Powered by ViewVC 1.1.26