Radreise-Wiki:MakeKML.pl: Unterschied zwischen den Versionen

Aus Radreise-Wiki
 
(3 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 8: Zeile 8:


  <nowiki>
  <nowiki>
use strict;
use strict;
 
use Encode qw(encode decode);
use Encode qw(encode decode);
 
# Default Settings
# Default Settings
require "ini.pl";
push @INC, '.';
my ($baseDir, $outDir, $username, $password, $encoding, $encAnsi, $encOut) = getIni();
require "ini.pl";
my ($baseDir, $outDir, $username, $password, $encoding, $encAnsi, $encOut) = getIni();
my $routeFileName = "";
 
my $routeURL      = "";
my $routeFileName = "";
my $routeURL      = "";
if ($#ARGV != -1) {
 
if ($#ARGV != -1) {
$routeFileName = join " ", @ARGV;
 
$routeFileName = join " ", @ARGV;
if ($routeFileName =~ / \($/) {  
 
if ($routeFileName =~ / \($/) {  
$routeFileName .= "retour)";
}
$routeFileName .= "retour)";
}
} else {
 
} else {
my @content;
 
my @content;
open FIN, "$baseDir/RouteList.txt" or die "\n$! : $baseDir/RouteList.txt";
 
while (<FIN>) { push @content, decode $encoding, $_; }
open FIN, "$baseDir/RouteList.txt" or die "\n$! : $baseDir/RouteList.txt";
close (FIN);
while (<FIN>) { push @content, decode $encoding, $_; }
close (FIN);
my @content_s = reverse sort @content;
my @content_s = reverse sort @content;
my ($dateTXT, $dateKML, $type, $name) = split " :: ", $content_s[0];
my ($dateTXT, $dateKML, $type, $name) = split " :: ", $content_s[0];
chomp $name;
 
chomp $name;
$routeFileName = $name;
 
}
$routeFileName = $name;
}
my $routeFileName_e = encode $encAnsi, $routeFileName;
 
my $routeFileName_e = encode $encAnsi, $routeFileName;
$routeURL = encodeRouteNameURL($routeFileName);
 
$routeURL = encodeRouteNameURL($routeFileName);
print encode $encOut, "\n  Generating KML-File for $routeFileName\n";
 
print encode $encOut, "\n  Generating KML-File for $routeFileName\n";
#===================
 
# Reading Trackfile
#===================
# Reading Trackfile
open FIN, "$baseDir/tracks/$routeFileName_e.txt" or die "\n$! : $baseDir/tracks/$routeFileName_e.txt";
 
my $track = <FIN>;
open FIN, "$baseDir/tracks/$routeFileName_e.txt" or die "\n$! : $baseDir/tracks/$routeFileName_e.txt";
close (FIN);
my $track = <FIN>;
close (FIN);
open FIN, "$baseDir/text/$routeFileName_e.txt" or die "\n$! : $baseDir/text/$routeFileName_e.txt";
 
open FIN, "$baseDir/text/$routeFileName_e.txt" or die "\n$! : $baseDir/text/$routeFileName_e.txt";
my $ucontent = "";
 
while (<FIN>) { $ucontent .= $_; }
my $ucontent = "";
close FIN;
while (<FIN>) { $ucontent .= $_; }
my $content = decode ($encoding, $ucontent);
close FIN;
my $content = decode ($encoding, $ucontent);
if ($content !~ /
 
if ($content !~ /
{{TOC_Radfernweg}}\n
 
.*
\{\{TOC_Radfernweg}}\n
\n==\ Roadbook\ ==\n
.*
.*
\n==\ Roadbook\ ==\n
\n==\ GPS-Tracks\ ==\n
.*
.*
\n==\ GPS-Tracks\ ==\n
\[\[Kategorie:\s*(
.*
Fluss-Radfernweg|
\[\[Kategorie:\s*(
Anderer\ Radfernweg|
Fluss-Radfernweg|
Querverbindung|
Anderer\ Radfernweg|
Direktverbindung|
Querverbindung|
Fernroute|
Direktverbindung|
Regionaler\ Radwanderweg|
Radweit-Strecke|
Routenplaner\ Testroute|
Radreise|
Streckenvorschlag|
Fernroute|
Stadtrundfahrt
Regionaler\ Radwanderweg|
)\]\]
Routenplaner\ Testroute|
Streckenvorschlag|
/xs) {
Stadtrundfahrt
)
print encode $encOut, "Chapters in $routeFileName are not correct!\n";  
 
exit(1);
/xs) {
}
 
print encode $encOut, "Chapters in $routeFileName are not correct!\n";  
my @content  = split "\n", $content;
exit(1);
}
my  @routeFile = ();
 
push @routeFile, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
my @content  = split "\n", $content;
push @routeFile, "<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n";
 
push @routeFile, "<Document>\n";
my  @routeFile = ();
push @routeFile, " <name>$routeFileName</name>\n";
push @routeFile, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
push @routeFile, " <Metadata>\n";
push @routeFile, "<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n";
push @routeFile, " <![CDATA[<!--$routeURL-->]]>\n";
push @routeFile, "<Document>\n";
push @routeFile, " </Metadata>\n";
push @routeFile, " <name>$routeFileName</name>\n";
push @routeFile, " <open>0</open>\n";
push @routeFile, " <Metadata>\n";
push @routeFile, " <Placemark>\n";
push @routeFile, " <![CDATA[<!--$routeURL-->]]>\n";
push @routeFile, " <name>$routeFileName GPS-Track</name>\n";
push @routeFile, " </Metadata>\n";
push @routeFile, " <description>\n";
push @routeFile, " <open>0</open>\n";
push @routeFile, " <![CDATA[<a href=\"http://radreise-wiki.de/$routeURL\">Wiki</a>]]> \n";
push @routeFile, " <Placemark>\n";
push @routeFile, " </description>\n";
push @routeFile, " <name>$routeFileName GPS-Track</name>\n";
push @routeFile, " <Style>\n";
push @routeFile, " <description>\n";
push @routeFile, " <LineStyle>\n";
push @routeFile, " <![CDATA[<a href=\"http://radreise-wiki.de/$routeURL\">Wiki</a>]]> \n";
push @routeFile, " <color>ffff00ff</color>\n";
push @routeFile, " </description>\n";
push @routeFile, " <width>2</width>\n";
push @routeFile, " <Style>\n";
push @routeFile, " </LineStyle>\n";
push @routeFile, " <LineStyle>\n";
push @routeFile, " </Style>\n";
push @routeFile, " <color>ffff00ff</color>\n";
push @routeFile, " <LineString>\n";
push @routeFile, " <width>2</width>\n";
push @routeFile, " <tessellate>1</tessellate>\n";
push @routeFile, " </LineStyle>\n";
push @routeFile, " <coordinates>\n";
push @routeFile, " </Style>\n";
push @routeFile, " $track\n";
push @routeFile, " <LineString>\n";
push @routeFile, " </coordinates>\n";
push @routeFile, " <tessellate>1</tessellate>\n";
push @routeFile, " </LineString>\n";
push @routeFile, " <coordinates>\n";
push @routeFile, " </Placemark>\n";
push @routeFile, " $track\n";
push @routeFile, " <Folder>\n";
push @routeFile, " </coordinates>\n";
push @routeFile, " <name>Orte</name>\n";
push @routeFile, " </LineString>\n";
push @routeFile, " <open>0</open>\n";
push @routeFile, " </Placemark>\n";
push @routeFile, " <Folder>\n";
my $roadBook  = 0;
push @routeFile, " <name>Orte</name>\n";
my $place      = 0;
push @routeFile, " <open>0</open>\n";
my $touri      = 0;
 
my $geo        = 0;
my $roadBook  = 0;
my $lon        = 0;
my $place      = 0;
my $lat        = 0;
my $touri      = 0;
my $alt        = 0;
my $geo        = 0;
my $road      = 0;
my $lon        = 0;
my $kilo      = 0;
my $lat        = 0;
my $alt        = 0;
my $placeName  = "";
my $road      = 0;
my %placeName  = ();
my $kilo      = 0;
my $touriInfo  = "";
 
my $geoData    = "";
my $placeName  = "";
my $roadInfo  = "";
my %placeName  = ();
my $kilometer  = "";
my $touriInfo  = "";
my $geoData    = "";
foreach my $line (@content) {
my $roadInfo  = "";
my $kilometer  = "";
# Last Placemark is finished, Roadbook is finished
 
if (($roadBook) and ($line =~ /^== .* ==$/)) {
foreach my $line (@content) {
 
# Status-Übersicht
# Last Placemark is finished, Roadbook is finished
if ($touriInfo ne "") { $touri = 1; }
if (($roadBook) and ($line =~ /^== .* ==$/)) {
if ($roadInfo  ne "") { $road  = 1; }
 
# Status-Übersicht
my $placeNameURL = encodePlaceNameURL($placeName);
if ($touriInfo ne "") { $touri = 1; }
if ($roadInfo  ne "") { $road  = 1; }
if ($placeName{$placeName} > 1) {
 
$placeNameURL .= "_$placeName{$placeName}";
my $placeNameURL = encodePlaceNameURL($placeName);
}
 
if ($placeName{$placeName} > 1) {
push @routeFile, " <Placemark>\n";
$placeNameURL .= "_$placeName{$placeName}";
push @routeFile, " <name>$placeName</name>\n";
}
push @routeFile, " <visibility>0</visibility>\n";
 
push @routeFile, " <description>\n";
push @routeFile, " <Placemark>\n";
push @routeFile, " <![CDATA[<a href=\"http://radreise-wiki.de/$routeURL#$placeNameURL\">$routeFileName</a>]]> \n";
push @routeFile, " <name>$placeName</name>\n";
push @routeFile, " </description>\n";
push @routeFile, " <visibility>0</visibility>\n";
push @routeFile, " <Point>\n";
push @routeFile, " <description>\n";
push @routeFile, " <coordinates>\n";
push @routeFile, " <![CDATA[<a href=\"http://radreise-wiki.de/$routeURL#$placeNameURL\">$routeFileName</a>]]> \n";
push @routeFile, " $lon,$lat,$alt\n";
push @routeFile, " </description>\n";
push @routeFile, " </coordinates>\n";
push @routeFile, " <Point>\n";
push @routeFile, " </Point>\n";
push @routeFile, " <coordinates>\n";
push @routeFile, " </Placemark>\n";
push @routeFile, " $lon,$lat,$alt\n";
push @routeFile, " </coordinates>\n";
$roadBook  = 0;
push @routeFile, " </Point>\n";
$place    = 0;
push @routeFile, " </Placemark>\n";
$touri    = 0;
 
$geo      = 0;
$roadBook  = 0;
$lon      = 0;
$place    = 0;
$lat      = 0;
$touri    = 0;
$alt      = 0;
$geo      = 0;
$road      = 0;
$lon      = 0;
$kilo      = 0;
$lat      = 0;
$alt      = 0;
$placeName  = "";
$road      = 0;
%placeName  = ();
$kilo      = 0;
$touriInfo  = "";
 
$geoData    = "";
$placeName  = "";
$roadInfo  = "";
%placeName  = ();
$kilometer  = "";
$touriInfo  = "";
$geoData    = "";
# Start of Roadbook
$roadInfo  = "";
} elsif ($line =~ /^== Roadbook ==$/) {
$kilometer  = "";
 
$roadBook = 1;
# Start of Roadbook
} elsif ($line =~ /^== Roadbook ==$/) {
# A new Place within the Roadbook
 
} elsif ($roadBook and ($line =~ /^=== (.*) ===$/)) {
$roadBook = 1;
 
if ($place and not $kilo) {
# A new Place within the Roadbook
print "  No Kilometers: $routeFileName :: $placeName\n";
} elsif ($roadBook and ($line =~ /^=== (.*) ===$/)) {
#exit;
 
}
if ($place and not $kilo) {
print "  No Kilometers: $routeFileName :: $placeName\n";
# Save previous place
#exit;
if ($place) {
}
 
# Status-Übersicht
# Save previous place
if ($touriInfo ne "") { $touri = 1; }
if ($place) {
if ($roadInfo  ne "") { $road  = 1; }
 
# Status-Übersicht
my $placeNameURL = encodePlaceNameURL($placeName);
if ($touriInfo ne "") { $touri = 1; }
if ($roadInfo  ne "") { $road  = 1; }
if ($placeName{$placeName} > 1) {
 
$placeNameURL .= "_$placeName{$placeName}";
my $placeNameURL = encodePlaceNameURL($placeName);
}
 
if ($placeName{$placeName} > 1) {
push @routeFile, " <Placemark>\n";
$placeNameURL .= "_$placeName{$placeName}";
push @routeFile, " <name>$placeName</name>\n";
}
push @routeFile, " <visibility>0</visibility>\n";
 
push @routeFile, " <description>\n";
push @routeFile, " <Placemark>\n";
push @routeFile, " <![CDATA[<a href=\"http://radreise-wiki.de/$routeURL#$placeNameURL\">$routeFileName</a>]]> \n";
push @routeFile, " <name>$placeName</name>\n";
push @routeFile, " </description>\n";
push @routeFile, " <visibility>0</visibility>\n";
push @routeFile, " <Point>\n";
push @routeFile, " <description>\n";
push @routeFile, " <coordinates>\n";
push @routeFile, " <![CDATA[<a href=\"http://radreise-wiki.de/$routeURL#$placeNameURL\">$routeFileName</a>]]> \n";
push @routeFile, " $lon,$lat,$alt\n";
push @routeFile, " </description>\n";
push @routeFile, " </coordinates>\n";
push @routeFile, " <Point>\n";
push @routeFile, " </Point>\n";
push @routeFile, " <coordinates>\n";
push @routeFile, " </Placemark>\n";
push @routeFile, " $lon,$lat,$alt\n";
}
push @routeFile, " </coordinates>\n";
push @routeFile, " </Point>\n";
$place    = 1;
push @routeFile, " </Placemark>\n";
$touri    = 0;
}
$geo      = 0;
 
$lon      = 0;
$place    = 1;
$lat      = 0;
$touri    = 0;
$alt      = 0;
$geo      = 0;
$road      = 0;
$lon      = 0;
$kilo      = 0;
$lat      = 0;
$alt      = 0;
$placeName  = $1;
$road      = 0;
if (defined $placeName{$placeName}) {
$kilo      = 0;
$placeName{$placeName}++;
 
} else {
$placeName  = $1;
$placeName{$placeName} = 1;
if (defined $placeName{$placeName}) {
}
$placeName{$placeName}++;
} else {
$touriInfo  = "";
$placeName{$placeName} = 1;
$geoData    = "";
}
$roadInfo  = "";
 
$kilometer  = "";
$touriInfo  = "";
$geoData    = "";
#print "$routeFileName :: $placeName\n";
$roadInfo  = "";
$kilometer  = "";
# Geodata within the Placemark
 
} elsif ($place and ($line =~ /^{{Geodaten\|(.*)}}$/)) {
#print "$routeFileName :: $placeName\n";
 
$geo    = 1;
# Geodata within the Placemark
$geoData = $1;
} elsif ($place and ($line =~ /^\{\{Geodaten\|(.*)}}$/)) {
 
if ($geoData =~ /^([-]?\d+\.\d+)\|([-]?\d+\.\d+)\|([-]?\d+)\|([^\|]+)$/) {
$geo    = 1;
$geoData = $1;
$lat  = $1;
 
$lon  = $2;
if ($geoData =~ /^([-]?\d+\.\d+)\|([-]?\d+\.\d+)\|([-]?\d+)\|([^\|]+)$/) {
$alt  = $3;
 
$lat  = $1;
} else {
$lon  = $2;
print "Error in Geodata: $geoData\n";
$alt  = $3;
exit;
 
}
} else {
print "Error in Geodata: $geoData\n";
#print "      $geoData\n";
exit;
}
# Kilometrierung within Placemark
 
} elsif ($place and ($line =~ /^{{Kilometrierung\|(.*)}}$/)) {
#print "      $geoData\n";
 
if (not $geo) {
# Kilometrierung within Placemark
print "No Coordinates: $routeFileName :: $placeName\n";
} elsif ($place and ($line =~ /^\{\{Kilometrierung\|(.*)}}$/)) {
exit;
 
}
if (not $geo) {
print "No Coordinates: $routeFileName :: $placeName\n";
if ($kilo) {
exit;
print "  Multiple Kilometers: $routeFileName :: $placeName\n";
}
#exit;
 
}
if ($kilo) {
print "  Multiple Kilometers: $routeFileName :: $placeName\n";
$kilo      = 1;
#exit;
$kilometer = $1;
}
 
#print "      $kilometer\n";
$kilo      = 1;
$kilometer = $1;
# KilometrierungHm within Placemark
 
} elsif ($place and ($line =~ /^{{KilometrierungHm\|(.*)}}$/)) {
#print "      $kilometer\n";
 
if (not $geo) {
# KilometrierungHm within Placemark
print "No Coordinates: $routeFileName :: $placeName\n";
} elsif ($place and ($line =~ /^\{\{KilometrierungHm\|(.*)}}$/)) {
exit;
 
}
if (not $geo) {
print "No Coordinates: $routeFileName :: $placeName\n";
if ($kilo) {
exit;
print "  Multiple Kilometers: $routeFileName :: $placeName\n";
}
#exit;
 
}
if ($kilo) {
print "  Multiple Kilometers: $routeFileName :: $placeName\n";
$kilo      = 1;
#exit;
$kilometer = $1;
}
 
#print "      $kilometer\n";
$kilo      = 1;
$kilometer = $1;
# Empty Line
 
} elsif ($line =~ /^\s*$/) {
#print "      $kilometer\n";
 
} elsif ($line =~ /<br style="clear:both" \/>/) {
# KilometrierungHm6 within Placemark
} elsif ($place and ($line =~ /^\{\{KilometrierungHm6\|(.*)}}$/)) {
} elsif ($line =~ /\[\[Bild/) {
 
if (not $geo) {
} elsif ($place and not $geo and not $kilo) {
print "No Coordinates: $routeFileName :: $placeName\n";
exit;
$touriInfo .= "$line\n";
}
 
#print "      $line\n";
if ($kilo) {
print "  Multiple Kilometers: $routeFileName :: $placeName\n";
} elsif ($place and $geo and not $kilo) {
#exit;
}
$roadInfo .= "$line\n";
 
$kilo      = 1;
#print "      $line\n";
$kilometer = $1;
 
}
#print "      $kilometer\n";
}
 
# Empty Line
push @routeFile, " </Folder>\n";
} elsif ($line =~ /^\s*$/) {
push @routeFile, "</Document>\n";
 
push @routeFile, "</kml>\n";
} elsif ($line =~ /<br style="clear:both" \/>/) {
 
my $content = "";
} elsif ($line =~ /\[\[Bild/) {
foreach my $line (@routeFile) {
 
$content .= $line;
} elsif ($place and not $geo and not $kilo) {
}
 
$touriInfo .= "$line\n";
my $exitCode =0;
 
$exitCode = saveFileIfChangedOrNew ("$baseDir/kml/", "$routeFileName_e.kml", encode ($encoding, $content), 1);
#print "      $line\n";
 
exit($exitCode);
} elsif ($place and $geo and not $kilo) {
</nowiki>
 
$roadInfo .= "$line\n";
 
#print "      $line\n";
 
}
}
 
push @routeFile, " </Folder>\n";
push @routeFile, "</Document>\n";
push @routeFile, "</kml>\n";
 
my $content = "";
foreach my $line (@routeFile) {
$content .= $line;
}
 
my $exitCode =0;
$exitCode = saveFileIfChangedOrNew ("$baseDir/kml/", "$routeFileName_e.kml", encode ($encoding, $content), 1);
 
exit($exitCode);
</nowiki>
 
[[Kategorie: Verwaltungs-Software]]

Aktuelle Version vom 12. Januar 2018, 18:28 Uhr

Das Perl-Skript makeKML.pl wird mit dem Streckennamen als Parameter aufgerufen. Die zugehörige Streckendatei muss bereits im text- und die Trackdatei im track-Verzeichnis vorhanden sein. Beispiel für einen Aufruf:

perl makeKML.pl Donau

Das Skript fasst die Informationen aus dem Roadbook und dem Track zusammen und generiert eine GoogleEarth kompatible KML-Datei. Diese wird im kml-Verzeichnis gespeichert. Zusätzlich wird eine kmz-Datei im Output-Verzeichis (siehe ini.pl) gespeichert. Diese Datei kann manuell ins Wiki hochgeladen werden.

Quellcode des Skripts:

use strict;

use Encode qw(encode decode);

# Default Settings
push @INC, '.';
require "ini.pl";
my ($baseDir, $outDir, $username, $password, $encoding, $encAnsi, $encOut) = getIni();

my $routeFileName = "";
my $routeURL      = "";

if ($#ARGV != -1) {

	$routeFileName = join " ", @ARGV;

	if ($routeFileName =~ / \($/) { 
	
		$routeFileName .= "retour)";
	}

} else {

	my @content;

	open FIN, "$baseDir/RouteList.txt" or die "\n$! : $baseDir/RouteList.txt";
	while (<FIN>) { push @content, decode $encoding, $_; }
	close (FIN);
	
	my @content_s = reverse sort @content;
	
	my ($dateTXT, $dateKML, $type, $name) = split " :: ", $content_s[0];

	chomp $name;

	$routeFileName = $name;
}

my $routeFileName_e = encode $encAnsi, $routeFileName;

$routeURL = encodeRouteNameURL($routeFileName);

print encode $encOut, "\n   Generating KML-File for $routeFileName\n";

#===================
# Reading Trackfile

open FIN, "$baseDir/tracks/$routeFileName_e.txt" or die "\n$! : $baseDir/tracks/$routeFileName_e.txt";
my $track = <FIN>;
close (FIN);

open FIN, "$baseDir/text/$routeFileName_e.txt" or die "\n$! : $baseDir/text/$routeFileName_e.txt";

my $ucontent = "";
while (<FIN>) { $ucontent .= $_; }
close FIN;
my $content = decode ($encoding, $ucontent);

if ($content !~ /

	\{\{TOC_Radfernweg}}\n
	.*
	\n==\ Roadbook\ ==\n
	.*
	\n==\ GPS-Tracks\ ==\n
	.*
	\[\[Kategorie:\s*(
		Fluss-Radfernweg|
		Anderer\ Radfernweg|
		Querverbindung|
		Direktverbindung|
		Radweit-Strecke|
		Radreise|
		Fernroute|
		Regionaler\ Radwanderweg|
		Routenplaner\ Testroute|
		Streckenvorschlag|
		Stadtrundfahrt
	)

	/xs) {

	print encode $encOut, "Chapters in $routeFileName are not correct!\n"; 
	exit(1);
}

my @content   = split "\n", $content;

my   @routeFile = ();
push @routeFile, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
push @routeFile, "<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n";
push @routeFile, "<Document>\n";
push @routeFile, "	<name>$routeFileName</name>\n";
push @routeFile, "	<Metadata>\n";
push @routeFile, "		<![CDATA[<!--$routeURL-->]]>\n";
push @routeFile, "	</Metadata>\n";
push @routeFile, "	<open>0</open>\n";
push @routeFile, "	<Placemark>\n";
push @routeFile, "		<name>$routeFileName GPS-Track</name>\n";
push @routeFile, "		<description>\n";
push @routeFile, "			<![CDATA[<a href=\"http://radreise-wiki.de/$routeURL\">Wiki</a>]]> \n";
push @routeFile, "		</description>\n";
push @routeFile, "		<Style>\n";
push @routeFile, "			<LineStyle>\n";
push @routeFile, "				<color>ffff00ff</color>\n";
push @routeFile, "				<width>2</width>\n";
push @routeFile, "			</LineStyle>\n";
push @routeFile, "		</Style>\n";
push @routeFile, "		<LineString>\n";
push @routeFile, "			<tessellate>1</tessellate>\n";
push @routeFile, "			<coordinates>\n";
push @routeFile, "				$track\n";
push @routeFile, "			</coordinates>\n";
push @routeFile, "		</LineString>\n";
push @routeFile, "	</Placemark>\n";
push @routeFile, "	<Folder>\n";
push @routeFile, "		<name>Orte</name>\n";
push @routeFile, "		<open>0</open>\n";

my $roadBook   = 0;
my $place      = 0;
my $touri      = 0;
my $geo        = 0;
my $lon        = 0;
my $lat        = 0;
my $alt        = 0;
my $road       = 0;
my $kilo       = 0;

my $placeName  = "";
my %placeName  = ();
my $touriInfo  = "";
my $geoData    = "";
my $roadInfo   = "";
my $kilometer  = "";

foreach my $line (@content) {

	# Last Placemark is finished, Roadbook is finished
	if (($roadBook) and ($line =~ /^== .* ==$/)) {

		# Status-Übersicht
		if ($touriInfo ne "") { $touri = 1; }
		if ($roadInfo  ne "") { $road  = 1; }

		my $placeNameURL = encodePlaceNameURL($placeName);

		if ($placeName{$placeName} > 1) {
			$placeNameURL .= "_$placeName{$placeName}";
		}

		push @routeFile, "		<Placemark>\n";
		push @routeFile, "			<name>$placeName</name>\n";
		push @routeFile, "			<visibility>0</visibility>\n";
		push @routeFile, "			<description>\n";
		push @routeFile, "				<![CDATA[<a href=\"http://radreise-wiki.de/$routeURL#$placeNameURL\">$routeFileName</a>]]> \n";
		push @routeFile, "			</description>\n";
		push @routeFile, "			<Point>\n";
		push @routeFile, "				<coordinates>\n";
		push @routeFile, "					$lon,$lat,$alt\n";
		push @routeFile, "				</coordinates>\n";
		push @routeFile, "			</Point>\n";
		push @routeFile, "		</Placemark>\n";

		$roadBook  = 0;
		$place     = 0;
		$touri     = 0;
		$geo       = 0;
		$lon       = 0;
		$lat       = 0;
		$alt       = 0;
		$road      = 0;
		$kilo      = 0;

		$placeName  = "";
		%placeName  = ();
		$touriInfo  = "";
		$geoData    = "";
		$roadInfo   = "";
		$kilometer  = "";

	# Start of Roadbook
	} elsif ($line =~ /^== Roadbook ==$/) {

		$roadBook = 1;

	# A new Place within the Roadbook
	} elsif ($roadBook and ($line =~ /^=== (.*) ===$/)) {

		if ($place and not $kilo) {
			print "   No Kilometers: $routeFileName :: $placeName\n";
			#exit;
		}

		# Save previous place
		if ($place) {

			# Status-Übersicht
			if ($touriInfo ne "") { $touri = 1; }
			if ($roadInfo  ne "") { $road  = 1; }

			my $placeNameURL = encodePlaceNameURL($placeName);

			if ($placeName{$placeName} > 1) {
				$placeNameURL .= "_$placeName{$placeName}";
			}

			push @routeFile, "		<Placemark>\n";
			push @routeFile, "			<name>$placeName</name>\n";
			push @routeFile, "			<visibility>0</visibility>\n";
			push @routeFile, "			<description>\n";
			push @routeFile, "				<![CDATA[<a href=\"http://radreise-wiki.de/$routeURL#$placeNameURL\">$routeFileName</a>]]> \n";
			push @routeFile, "			</description>\n";
			push @routeFile, "			<Point>\n";
			push @routeFile, "				<coordinates>\n";
			push @routeFile, "					$lon,$lat,$alt\n";
			push @routeFile, "				</coordinates>\n";
			push @routeFile, "			</Point>\n";
			push @routeFile, "		</Placemark>\n";
		}

		$place     = 1;
		$touri     = 0;
		$geo       = 0;
		$lon       = 0;
		$lat       = 0;
		$alt       = 0;
		$road      = 0;
		$kilo      = 0;

		$placeName  = $1;
		if (defined $placeName{$placeName}) {
			$placeName{$placeName}++;
		} else {
			$placeName{$placeName} = 1;
		}

		$touriInfo  = "";
		$geoData    = "";
		$roadInfo   = "";
		$kilometer  = "";

		#print "$routeFileName :: $placeName\n";

	# Geodata within the Placemark
	} elsif ($place and ($line =~ /^\{\{Geodaten\|(.*)}}$/)) {

		$geo     = 1;
		$geoData = $1;

		if ($geoData =~ /^([-]?\d+\.\d+)\|([-]?\d+\.\d+)\|([-]?\d+)\|([^\|]+)$/) {

			$lat  = $1;
			$lon  = $2;
			$alt  = $3;

		} else {
			print "Error in Geodata: $geoData\n";
			exit;
		}

		#print "      $geoData\n";

	# Kilometrierung within Placemark
	} elsif ($place and ($line =~ /^\{\{Kilometrierung\|(.*)}}$/)) {

		if (not $geo) {
			print "No Coordinates: $routeFileName :: $placeName\n";
			exit;
		}

		if ($kilo) {
			print "   Multiple Kilometers: $routeFileName :: $placeName\n";
			#exit;
		}

		$kilo      = 1;
		$kilometer = $1;

		#print "      $kilometer\n";

	# KilometrierungHm within Placemark
	} elsif ($place and ($line =~ /^\{\{KilometrierungHm\|(.*)}}$/)) {

		if (not $geo) {
			print "No Coordinates: $routeFileName :: $placeName\n";
			exit;
		}

		if ($kilo) {
			print "   Multiple Kilometers: $routeFileName :: $placeName\n";
			#exit;
		}

		$kilo      = 1;
		$kilometer = $1;

		#print "      $kilometer\n";

	# KilometrierungHm6 within Placemark
	} elsif ($place and ($line =~ /^\{\{KilometrierungHm6\|(.*)}}$/)) {

		if (not $geo) {
			print "No Coordinates: $routeFileName :: $placeName\n";
			exit;
		}

		if ($kilo) {
			print "   Multiple Kilometers: $routeFileName :: $placeName\n";
			#exit;
		}

		$kilo      = 1;
		$kilometer = $1;

		#print "      $kilometer\n";

	# Empty Line
	} elsif ($line =~ /^\s*$/) {

	} elsif ($line =~ /<br style="clear:both" \/>/) {

	} elsif ($line =~ /\[\[Bild/) {

	} elsif ($place and not $geo and not $kilo) {

		$touriInfo .= "$line\n";

		#print "      $line\n";

	} elsif ($place and $geo and not $kilo) {

		$roadInfo .= "$line\n";

		#print "      $line\n";

	}
}

push @routeFile, "	</Folder>\n";
push @routeFile, "</Document>\n";
push @routeFile, "</kml>\n";

my $content = "";
foreach my $line (@routeFile) {
	$content .= $line;
}

my $exitCode =0;
$exitCode = saveFileIfChangedOrNew ("$baseDir/kml/", "$routeFileName_e.kml", encode ($encoding, $content), 1);

exit($exitCode);