/[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 17 by dpavlin, Mon Dec 3 14:57:48 2007 UTC revision 20 by dpavlin, Mon Dec 3 20:52:33 2007 UTC
# Line 10  use NMEA; Line 10  use NMEA;
10    
11  my $path = shift @ARGV || die "usage: $0 nmea_dump.gps\n";  my $path = shift @ARGV || die "usage: $0 nmea_dump.gps\n";
12    
13    my $individual_placemarks = 0;
14    
15  open(my $fh, '<', $path) || die "can't open $path: $!";  open(my $fh, '<', $path) || die "can't open $path: $!";
16    
17  print qq{<?xml version="1.0" encoding="UTF-8"?>  my $out_path = $path;
18    $out_path =~ s!^.*?([^/]+)\.[^/]+$!$1!; #!
19    $out_path .= '.kml';
20    
21    open(my $out, '>', $out_path) || die "can't open $out_path: $!";
22    
23    print $out qq{<?xml version="1.0" encoding="UTF-8"?>
24  <kml xmlns="http://earth.google.com/kml/2.2">  <kml xmlns="http://earth.google.com/kml/2.2">
25  <Document>  <Document>
26          <name>$path</name>          <name>$path</name>
# Line 20  print qq{<?xml version="1.0" encoding="U Line 28  print qq{<?xml version="1.0" encoding="U
28                  <name>NMEA trace</name>                  <name>NMEA trace</name>
29  };  };
30    
31    print $out qq{
32                    <Placemark id='linestring1'>
33                            <name>$path</name>
34                            <LineString>
35                            <extrude>1</extrude>
36                            <altitudeMode>relativeToGround</altitudeMode>
37                            <coordinates>
38    } unless $individual_placemarks;
39    
40  my $point = 0;  my $point = 0;
41    
# Line 28  while(<$fh>) { Line 44  while(<$fh>) {
44    
45          $point++;          $point++;
46    
47          print qq{          if ( $individual_placemarks ) {
48          <Placemark>  
49                  <name>$point</name>                  print $out qq{
50                  <description>                  <Placemark>
51          }, join(' ', map { ucfirst($_) . ':' . $hash->{$_} } ( qw/time lat lon speed course date var var_ew/ ) ), qq{                          <name>$point</name>
52                  </description>                          <description>
53                  <Point>                  }, join(' ', map { ucfirst($_) . ':' . $hash->{$_} } ( qw/time lat lon speed course date var var_ew/ ) ), qq{
54                          <coordinates>}, $hash->{lon}, ',', $hash->{lat}, qq{,0</coordinates>                          </description>
55                  </Point>                          <Point>
56          </Placemark>                                  <coordinates>}, $hash->{lon}, ',', $hash->{lat}, qq{,0</coordinates>
57          };                          </Point>
58                    </Placemark>
59                    };
60    
61            } else {
62                    print $out $hash->{lon}, ',', $hash->{lat}, 0, "\n";
63            }
64  }  }
65    
66  print qq{  print $out qq{
67                            </coordinates>
68                            </LineString>
69                    </Placemark>
70    } unless $individual_placemarks;
71    
72    print $out qq{
73          </Folder>          </Folder>
74  </Document>  </Document>
75  </kml>  </kml>
76  };  };
77    
78  warn "Produced $point points from $path\n";  warn "Produced $point points from $path -> $out_path\n";

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

  ViewVC Help
Powered by ViewVC 1.1.26