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

Contents of /bin/nmea2kml.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 21 - (show annotations)
Mon Dec 3 21:37:25 2007 UTC (13 years, 6 months ago) by dpavlin
File MIME type: text/plain
File size: 1694 byte(s)
by default save placemarks *AND* lines (disable them with
--no-placemarks or --no-lines)
1 #!/usr/bin/perl
2
3 # Convert GPS NMEA dump into Google's kml file
4
5 use strict;
6 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 '../';
19 use NMEA;
20
21 my $path = shift @ARGV || die "usage: $0 nmea_dump.gps\n";
22
23 open(my $fh, '<', $path) || die "can't open $path: $!";
24
25 my $out_path = $path;
26 $out_path =~ s!^.*?([^/]+)$!$1!; #!
27 $out_path .= '.kml';
28
29 open(my $out, '>', $out_path) || die "can't open $out_path: $!";
30
31 print $out qq{<?xml version="1.0" encoding="UTF-8"?>
32 <kml xmlns="http://earth.google.com/kml/2.2">
33 <Document>
34 <name>$path</name>
35 <Folder>
36 <name>NMEA trace</name>
37 };
38
39 print $out qq{
40 <Placemark id='linestring1'>
41 <name>Line</name>
42 <LineString>
43 <extrude>1</extrude>
44 <altitudeMode>relativeToGround</altitudeMode>
45 <coordinates>
46 } if $line;
47
48 my $point = 0;
49 my @placemarks;
50
51 while(<$fh>) {
52 my $hash = NMEA->line( $_ ) || next;
53
54 $point++;
55
56 if ( $placemarks ) {
57 push @placemarks, qq{
58 <Placemark>
59 <name>$point</name>
60 <description>
61 }, join(' ', map { ucfirst($_) . ':' . $hash->{$_} } ( qw/time lat lon speed course date var var_ew/ ) ), qq{
62 </description>
63 <Point>
64 <coordinates>}, join(',', $hash->{lon}, $hash->{lat}, 0), qq{</coordinates>
65 </Point>
66 </Placemark>
67 };
68 }
69
70 print $out join(',', $hash->{lon}, $hash->{lat}, 0), "\n" if $line;
71 }
72
73 print $out qq{
74 </coordinates>
75 </LineString>
76 </Placemark>
77 } 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{
89 </Folder>
90 </Document>
91 </kml>
92 };
93
94 warn "Produced $point points from $path -> $out_path\n";

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26