/[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 20 - (show annotations)
Mon Dec 3 20:52:33 2007 UTC (16 years, 6 months ago) by dpavlin
File MIME type: text/plain
File size: 1508 byte(s)
create also paths in kml instead of individual placemarks
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 lib '../';
9 use NMEA;
10
11 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: $!";
16
17 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">
25 <Document>
26 <name>$path</name>
27 <Folder>
28 <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;
41
42 while(<$fh>) {
43 my $hash = NMEA->line( $_ ) || next;
44
45 $point++;
46
47 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 }
65
66 print $out qq{
67 </coordinates>
68 </LineString>
69 </Placemark>
70 } unless $individual_placemarks;
71
72 print $out qq{
73 </Folder>
74 </Document>
75 </kml>
76 };
77
78 warn "Produced $point points from $path -> $out_path\n";

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26