Skip to content

Instantly share code, notes, and snippets.

@lukec
Created March 6, 2016 00:06
Show Gist options
  • Save lukec/9a2ec88f46bcb97a8d29 to your computer and use it in GitHub Desktop.
Save lukec/9a2ec88f46bcb97a8d29 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use XML::Simple;
# USAGE: cat your-file.kml | perl art-kml-to-csv > your-file.csv
#
# This script reads from standard input and writes to standard output.
# Pipe your file into this script
my $xml = XMLin(join '', <STDIN>);
print "TITLE, NAME, URL, GEO\n";
my $placemarks = $xml->{Document}{Folder}{Placemark};
for my $k (keys %$placemarks) {
my $p = $placemarks->{$k};
# Grab the data attributes of this placemark
my $data = $p->{ExtendedData}{SchemaData}{SimpleData} // {};
my $name = $data->{NAME}{content} // '';
my $title = $data->{TITLE}{content} // '';
my $link = $data->{URL_LINK}{content} // '';
$link =~ s#^.+http#http#;
$link =~ s#'.+##;
my $geo = $p->{Point}{coordinates} // '';
print qq("$title", "$name", "$link", "$geo"\n);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment