mirror of
https://gitlab.com/tiggr/enex2kml.git
synced 2024-12-25 00:11:01 +01:00
added CSV export
This commit is contained in:
parent
782fa6f694
commit
a5625b89c7
114
enex2kml.pl
114
enex2kml.pl
@ -24,12 +24,15 @@ my $verbose = 0;
|
|||||||
my $showSkipped = 0;
|
my $showSkipped = 0;
|
||||||
my $foldername = 'Evernote';
|
my $foldername = 'Evernote';
|
||||||
my $help = 0;
|
my $help = 0;
|
||||||
|
my $csv = 0;
|
||||||
|
my @csvdata = ();
|
||||||
|
|
||||||
GetOptions( 'i|input=s' => \$inFile,
|
GetOptions( 'i|input=s' => \$inFile,
|
||||||
'o|output=s' => \$outFile,
|
'o|output=s' => \$outFile,
|
||||||
'v|verbose' => \$verbose,
|
'v|verbose' => \$verbose,
|
||||||
's|showSkipped' => \$showSkipped,
|
's|showSkipped' => \$showSkipped,
|
||||||
'f|folder=s' => \$foldername,
|
'f|folder=s' => \$foldername,
|
||||||
|
'c|csv' => \$csv,
|
||||||
'h|help' => \$help);
|
'h|help' => \$help);
|
||||||
|
|
||||||
if ($help || $inFile eq '' || $outFile eq '') {
|
if ($help || $inFile eq '' || $outFile eq '') {
|
||||||
@ -40,40 +43,47 @@ if ($help || $inFile eq '' || $outFile eq '') {
|
|||||||
|
|
||||||
my $parser = XML::LibXML->new();
|
my $parser = XML::LibXML->new();
|
||||||
my $notes = $parser->parse_file($inFile);
|
my $notes = $parser->parse_file($inFile);
|
||||||
|
my $kml;
|
||||||
|
my $folder;
|
||||||
|
my $root;
|
||||||
|
my $document;
|
||||||
|
|
||||||
my $kml = XML::LibXML::Document->new('1.0', 'utf-8');
|
if ($csv == 0) {
|
||||||
my $root = $kml->createElement('kml');
|
$kml = XML::LibXML::Document->new('1.0', 'utf-8');
|
||||||
$root->setAttribute('xmlns'=> 'http://www.opengis.net/kml/2.2');
|
$root = $kml->createElement('kml');
|
||||||
my $document = $kml->createElement('Document');
|
$root->setAttribute('xmlns'=> 'http://www.opengis.net/kml/2.2');
|
||||||
my $folder = $kml->createElement('Folder');
|
$document = $kml->createElement('Document');
|
||||||
my $name = $kml->createElement('name');
|
$folder = $kml->createElement('Folder');
|
||||||
$name->appendTextNode($foldername);
|
my $name = $kml->createElement('name');
|
||||||
$root->appendChild($document);
|
$name->appendTextNode($foldername);
|
||||||
$folder->appendChild($name);
|
$root->appendChild($document);
|
||||||
$kml->setDocumentElement($root);
|
$folder->appendChild($name);
|
||||||
|
$kml->setDocumentElement($root);
|
||||||
|
|
||||||
my $style = $kml->createElement('Style');
|
my $style = $kml->createElement('Style');
|
||||||
$style->setAttribute('id' => 'done_style');
|
$style->setAttribute('id' => 'done_style');
|
||||||
my $iconStyle = $kml->createElement('IconStyle');
|
my $iconStyle = $kml->createElement('IconStyle');
|
||||||
$style->appendChild($iconStyle);
|
$style->appendChild($iconStyle);
|
||||||
my $scale = $kml->createElement('scale');
|
my $scale = $kml->createElement('scale');
|
||||||
$scale->appendTextNode('1.3');
|
$scale->appendTextNode('1.3');
|
||||||
$iconStyle->appendChild($scale);
|
$iconStyle->appendChild($scale);
|
||||||
my $icon = $kml->createElement('Icon');
|
my $icon = $kml->createElement('Icon');
|
||||||
$iconStyle->appendChild($icon);
|
$iconStyle->appendChild($icon);
|
||||||
my $href = $kml->createElement('href');
|
my $href = $kml->createElement('href');
|
||||||
$href->appendTextNode('http://maps.google.com/mapfiles/kml/pushpin/grn-pushpin.png');
|
$href->appendTextNode('http://maps.google.com/mapfiles/kml/pushpin/grn-pushpin.png');
|
||||||
$icon->appendChild($href);
|
$icon->appendChild($href);
|
||||||
my $hotspot = $kml->createElement('hotSpot');
|
my $hotspot = $kml->createElement('hotSpot');
|
||||||
$hotspot->setAttribute('x', '20');
|
$hotspot->setAttribute('x', '20');
|
||||||
$hotspot->setAttribute('y', '2');
|
$hotspot->setAttribute('y', '2');
|
||||||
$hotspot->setAttribute('xunits', 'pixels');
|
$hotspot->setAttribute('xunits', 'pixels');
|
||||||
$hotspot->setAttribute('yunits', 'pixels');
|
$hotspot->setAttribute('yunits', 'pixels');
|
||||||
$icon->appendChild($hotspot);
|
$icon->appendChild($hotspot);
|
||||||
|
|
||||||
$document->appendChild($style);
|
$document->appendChild($style);
|
||||||
$document->appendChild($folder);
|
$document->appendChild($folder);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
foreach my $note ($notes->findnodes('/en-export/note')) {
|
foreach my $note ($notes->findnodes('/en-export/note')) {
|
||||||
my($title) = $note->findnodes('./title');
|
my($title) = $note->findnodes('./title');
|
||||||
my($lat) = $note->findnodes('./note-attributes/latitude');
|
my($lat) = $note->findnodes('./note-attributes/latitude');
|
||||||
@ -100,30 +110,41 @@ if ($help || $inFile eq '' || $outFile eq '') {
|
|||||||
if ($lat && $long && $lat->to_literal != 0 && $long->to_literal != 0) {
|
if ($lat && $long && $lat->to_literal != 0 && $long->to_literal != 0) {
|
||||||
$exported++;
|
$exported++;
|
||||||
|
|
||||||
my $place = $kml->createElement('Placemark');
|
if ($csv == 0) {
|
||||||
my $name = $kml->createElement('name');
|
my $place = $kml->createElement('Placemark');
|
||||||
$name->appendTextNode($title->to_literal);
|
my $name = $kml->createElement('name');
|
||||||
|
$name->appendTextNode($title->to_literal);
|
||||||
|
|
||||||
my $point = $kml->createElement('Point');
|
my $point = $kml->createElement('Point');
|
||||||
my $coord = $kml->createElement('coordinates');
|
my $coord = $kml->createElement('coordinates');
|
||||||
$coord->appendTextNode($long->to_literal.','.$lat->to_literal.',0');
|
$coord->appendTextNode($long->to_literal.','.$lat->to_literal.',0');
|
||||||
$point->appendChild($coord);
|
$point->appendChild($coord);
|
||||||
my $styleurl = $kml->createElement('styleUrl');
|
my $styleurl = $kml->createElement('styleUrl');
|
||||||
$styleurl->appendTextNode('#done_style');
|
$styleurl->appendTextNode('#done_style');
|
||||||
|
|
||||||
$place->appendChild($name);
|
$place->appendChild($name);
|
||||||
if ($done eq 'Yes') { $place->appendChild($styleurl); }
|
if ($done eq 'Yes') { $place->appendChild($styleurl); }
|
||||||
$place->appendChild($point);
|
$place->appendChild($point);
|
||||||
$folder->appendChild($place);
|
$folder->appendChild($place);
|
||||||
|
} else {
|
||||||
|
my $t = '"'.$title->to_literal.'"';
|
||||||
|
push(@csvdata, join(',', $long->to_literal, $lat->to_literal, $t));
|
||||||
|
}
|
||||||
} elsif ($showSkipped) {
|
} elsif ($showSkipped) {
|
||||||
print encode_utf8("Skipped: ".$title->to_literal."\n");
|
print encode_utf8("Skipped: ".$title->to_literal."\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
open KMLOUT, ">", $outFile or die $!;
|
if ($csv == 0) {
|
||||||
print KMLOUT $kml->toString(1);
|
open KMLOUT, ">", $outFile or die $!;
|
||||||
close KMLOUT;
|
print KMLOUT $kml->toString(1);
|
||||||
|
close KMLOUT;
|
||||||
|
} else {
|
||||||
|
open CSVOUT, ">", $outFile or die $!;
|
||||||
|
foreach (@csvdata) { print CSVOUT $_."\n"; }
|
||||||
|
close CSVOUT;
|
||||||
|
}
|
||||||
|
|
||||||
my $skipped = $count-$exported;
|
my $skipped = $count-$exported;
|
||||||
print "\ninput:\t$inFile\n";
|
print "\ninput:\t$inFile\n";
|
||||||
@ -156,6 +177,7 @@ please visit http://creativecommons.org/licenses/by-sa/3.0/deed.de
|
|||||||
o|output file to write/overwrite
|
o|output file to write/overwrite
|
||||||
v|verbose show more infos
|
v|verbose show more infos
|
||||||
s|showSkipped show skipped entries
|
s|showSkipped show skipped entries
|
||||||
|
c|csv save in csv for Navigon instead of kml
|
||||||
f|folder foldername in kml/Google Earth
|
f|folder foldername in kml/Google Earth
|
||||||
h|help show this help
|
h|help show this help
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user