#!/usr/bin/perl # # pcx5tokml.pl [-o output-file] <description> # # Convert PCX5 format to KML # # $Id: pcx5tokml.pl,v 1.4 2005/12/08 19:54:30 cvsremote Exp $ # # sub usage { printf(stderr "Usage: pcx5tokml.pl [-o output-file] <pcx5-file> <title> <description>\n"); exit(1); } # # main # $outFile = ""; # init $suffix = "kml"; # outFile suffix usage() if ($#ARGV < 2 || $#ARGV == 3); if ($#ARGV >= 4) { usage() if ($ARGV[0] ne "-o"); $outFile = $ARGV[1]; shift; shift; } $file = $ARGV[0]; $title = $ARGV[1]; $desc = $ARGV[2]; if ($outFile eq "") { if ($file =~ /^(.*\.)(.*)$/) { $outFile = $1 . $suffix; } else { $outFile = $file . "." . $suffix; } $outFile = substr($outFile, rindex($outFile, "/") + 1); } open(FILE, $file) || die "can't open $file\n"; open(O_FILE, ">$outFile") || die "can't open $outFile\n"; print O_FILE <<__EOF__; <?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://earth.google.com/kml/2.0"> <Placemark> <description>$desc</description> <name>$title</name> <visibility>1</visibility> <open>1</open> <Style> <LineStyle> <color>ff0000ff</color> <width>5</width> </LineStyle> <PolyStyle> <color>7f00ff00</color> </PolyStyle> </Style> <LineString> <extrude>1</extrude> <tessellate>1</tessellate> <altitudeMode>absolute</altitudeMode> <coordinates> __EOF__ while(<FILE>) { next unless (/^T/); split; if ($_[1] =~ /N(\d\d)(.*)/) { $lat = $1 + ($2/60.0); } if ($_[2] =~ /W(\d\d\d)(.*)/) { $long = $1 + ($2/60.0); $long *= -1.0; } printf(O_FILE "%f,%f,%f\n", $long, $lat, $_[5]); } close(FILE); printf O_FILE <<__EOF__; </coordinates> </LineString> </Placemark> </kml> __EOF__ close(O_FILE);