#!/usr/bin/perl
# Make KML from a list of air waypoints
# Copyright       : http://www.fsf.org/copyleft/gpl.html
# Author          : Dan Jacobson -- http://jidanni.org/
# Created On      : Sun Nov 10 07:55:07 2013
# Last Modified On: Tue Nov 12 10:44:21 2013
# Update Count    : 33
use strict;
use warnings FATAL => 'all';
print <<\EOF;
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Document>
    <name>航路</name>
EOF
my @coordinates;
while (<>) {
    my @F = split;
    push @coordinates, "$F[2],$F[1]," . sprintf "%.0f", 27000 * 0.3048;
    if (eof) {
        my $c = join " ", @coordinates;
        my $name = $ARGV;
        $name =~ s/\..*//;
        print <<EOF;
    <Placemark>
      <name>$name</name>
      <LineString>
        <altitudeMode>absolute</altitudeMode>
        <coordinates>$c</coordinates>
      </LineString>
    </Placemark>
EOF
        undef @coordinates;
    }
}
print <<\EOF;
  </Document>
</kml>
EOF
