/[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

Annotation of /bin/nmea2kml.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 20 - (hide annotations)
Mon Dec 3 20:52:33 2007 UTC (16 years, 5 months ago) by dpavlin
File MIME type: text/plain
File size: 1508 byte(s)
create also paths in kml instead of individual placemarks
1 dpavlin 14 #!/usr/bin/perl
2    
3     # Convert GPS NMEA dump into Google's kml file
4    
5     use strict;
6     use warnings;
7    
8     use lib '../';
9     use NMEA;
10    
11     my $path = shift @ARGV || die "usage: $0 nmea_dump.gps\n";
12    
13 dpavlin 20 my $individual_placemarks = 0;
14    
15 dpavlin 14 open(my $fh, '<', $path) || die "can't open $path: $!";
16    
17 dpavlin 20 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 dpavlin 14 <kml xmlns="http://earth.google.com/kml/2.2">
25     <Document>
26     <name>$path</name>
27     <Folder>
28     <name>NMEA trace</name>
29     };
30    
31 dpavlin 20 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 dpavlin 14
40     my $point = 0;
41    
42     while(<$fh>) {
43     my $hash = NMEA->line( $_ ) || next;
44    
45     $point++;
46    
47 dpavlin 20 if ( $individual_placemarks ) {
48    
49     print $out qq{
50     <Placemark>
51     <name>$point</name>
52     <description>
53     }, join(' ', map { ucfirst($_) . ':' . $hash->{$_} } ( qw/time lat lon speed course date var var_ew/ ) ), qq{
54     </description>
55     <Point>
56     <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 dpavlin 14 }
65    
66 dpavlin 20 print $out qq{
67     </coordinates>
68     </LineString>
69     </Placemark>
70     } unless $individual_placemarks;
71    
72     print $out qq{
73 dpavlin 14 </Folder>
74     </Document>
75     </kml>
76     };
77 dpavlin 17
78 dpavlin 20 warn "Produced $point points from $path -> $out_path\n";

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26