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

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


  <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 $selectedType;
 
my $selectedType;
if ($ARGV[0]) {
 
if ($ARGV[0]) {
$selectedType = $ARGV[0];
 
$selectedType = $ARGV[0];
} else {
 
} else {
$selectedType = "H";
 
}
$selectedType = "H";
}
# ==================
 
# Reading RouteList
# ==================
# Reading RouteList
my @routeList;
 
my @routeList;
open FIN, "$baseDir/RouteList.txt" or die "$! : $baseDir/RouteList.txt";
 
while (<FIN>) { push @routeList, decode $encoding, $_; }
open FIN, "$baseDir/RouteList.txt" or die "$! : $baseDir/RouteList.txt";
close (FIN);
while (<FIN>) { push @routeList, decode $encoding, $_; }
close (FIN);
my @routeFile              = ();
 
my @Fluss_Radfernweg        = ();
my @routeFile              = ();
my @Anderer_Radfernweg      = ();
my @Fluss_Radfernweg        = ();
my @Querverbindung          = ();
my @Anderer_Radfernweg      = ();
my @Radweit_Strecke        = ();
my @Querverbindung          = ();
my @Regionaler_Radwanderweg = ();
my @Radweit_Strecke        = ();
my @Regionaler_Radwanderweg = ();
my $routeName;
 
my $routeFileName;
my $routeName;
my $routeURL;
my $routeFileName;
my $category;
my $routeURL;
my $counter;
my $category;
my $counter;
foreach my $line (@routeList) {
 
foreach my $line (@routeList) {
(my $dateTXT, my $dateKML, my $type, $routeName) = split " :: ", $line;
 
(my $dateTXT, my $dateKML, my $type, $routeName) = split " :: ", $line;
chomp($routeName);
 
chomp($routeName);
if ($type eq $selectedType) {
 
if ($type eq $selectedType) {
$counter ++;
 
$counter ++;
$routeFileName = encode $encAnsi, $routeName;
 
$routeFileName = encode $encAnsi, $routeName;
$routeURL = encodeRouteNameURL($routeFileName);
 
$routeURL = encodeRouteNameURL($routeFileName);
# ==================
 
# Reading Trackfile
# ==================
# Reading Trackfile
print encode $encOut, "Reading Trackfile : $routeFileName\n";
 
print encode $encOut, "Reading Trackfile : $routeFileName\n";
open FIN, "$baseDir/tracks/$routeFileName.txt" or die "$! : $baseDir/tracks/$routeFileName.txt";
 
my $track = <FIN>;
open FIN, "$baseDir/tracks/$routeFileName.txt" or die "$! : $baseDir/tracks/$routeFileName.txt";
close (FIN);
my $track = <FIN>;
close (FIN);
 
# =================
 
# Reading Textfile
# =================
# Reading Textfile
print encode $encOut, "Reading Textfile  : $routeFileName\n";
 
print encode $encOut, "Reading Textfile  : $routeFileName\n";
my $content;
 
open FILE, "$baseDir/text/$routeFileName.txt" or die "$baseDir/text/$routeFileName.txt: $!";
my $content;
while (<FILE>) { $content .= decode $encoding, $_; }
open FILE, "$baseDir/text/$routeFileName.txt" or die "$baseDir/text/$routeFileName.txt: $!";
close FILE;
while (<FILE>) { $content .= decode $encoding, $_; }
close FILE;
 
# =============
 
# Check Layout
# =============
# Check Layout
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|
Regionaler\ Radwanderweg|
Radweit-Strecke|
Routenplaner\ Testroute|
Direktverbindung|
Fernroute|
Regionaler\ Radwanderweg|
Streckenvorschlag|
Routenplaner\ Testroute|
Stadtrundfahrt
Radreise|
)\]\]
Fernroute|
Streckenvorschlag|
/xs) {
Stadtrundfahrt
)
print encode $encOut, "Chapters in $routeName are not correct!\n";  
 
exit(1);
/xs) {
}
 
print encode $encOut, "Chapters in $routeName are not correct!\n";  
$category = $1;
exit(1);
}
if (($category eq "Regionaler Radwanderweg") or  
 
($category eq "Streckenvorschlag") or
$category = $1;
($category eq "Stadtrundfahrt") or
 
($category eq "Fernroute")
if (($category eq "Regionaler Radwanderweg") or  
) {
($category eq "Streckenvorschlag") or
($category eq "Stadtrundfahrt") or
$category = "Anderer Radfernweg";
($category eq "Radreise") or
}
($category eq "Radweit-Strecke") or
($category eq "Fernroute")
# =============
) {
# Get Roadbook
 
$category = "Anderer Radfernweg";
my $pre_Roadbook;
}
my $Roadbook;
 
my $post_Roadbook;
# =============
# Get Roadbook
if ( $content =~ /(.*?== Roadbook ==.*?)(===.*?)(\n== .*)/s ) {
 
my $pre_Roadbook;
$pre_Roadbook  = $1;
my $Roadbook;
$Roadbook      = $2;
my $post_Roadbook;
$post_Roadbook = $3;
 
if ( $content =~ /(.*?== Roadbook ==.*?)(===.*?)(\n== .*)/s ) {
} else { die "Wrong Roadbook Format\n"; }
 
$pre_Roadbook  = $1;
my @Roadbook = split "\n", $Roadbook;
$Roadbook      = $2;
$post_Roadbook = $3;
 
# ===============
} else { die "Wrong Roadbook Format\n"; }
# Get Placemarks
 
my @Roadbook = split "\n", $Roadbook;
my @content  = split "\n", $content;
 
 
@routeFile = ();
# ===============
# Get Placemarks
push @routeFile, " <name>$routeName</name>\n";
 
push @routeFile, " <Metadata>\n";
my @content  = split "\n", $content;
push @routeFile, " <![CDATA[<!--$routeURL-->]]>\n";
 
push @routeFile, " </Metadata>\n";
@routeFile = ();
push @routeFile, " <open>0</open>\n";
 
push @routeFile, " <Placemark>\n";
push @routeFile, " <name>$routeName</name>\n";
push @routeFile, " <name>$routeName GPS-Track</name>\n";
push @routeFile, " <Metadata>\n";
push @routeFile, " <description>\n";
push @routeFile, " <![CDATA[<!--$routeURL-->]]>\n";
push @routeFile, " <![CDATA[<a href=\"http://radreise-wiki.de/$routeURL\">Wiki</a>]]> \n";
push @routeFile, " </Metadata>\n";
push @routeFile, " </description>\n";
push @routeFile, " <open>0</open>\n";
push @routeFile, " <Style>\n";
push @routeFile, " <Placemark>\n";
push @routeFile, " <LineStyle>\n";
push @routeFile, " <name>$routeName GPS-Track</name>\n";
push @routeFile, " <color>ffff00ff</color>\n";
push @routeFile, " <description>\n";
push @routeFile, " <width>2</width>\n";
push @routeFile, " <![CDATA[<a href=\"http://radreise-wiki.de/$routeURL\">Wiki</a>]]> \n";
push @routeFile, " </LineStyle>\n";
push @routeFile, " </description>\n";
push @routeFile, " </Style>\n";
push @routeFile, " <Style>\n";
push @routeFile, " <LineString>\n";
push @routeFile, " <LineStyle>\n";
push @routeFile, " <tessellate>1</tessellate>\n";
push @routeFile, " <color>ffff00ff</color>\n";
push @routeFile, " <coordinates>\n";
push @routeFile, " <width>2</width>\n";
push @routeFile, " $track\n";
push @routeFile, " </LineStyle>\n";
push @routeFile, " </coordinates>\n";
push @routeFile, " </Style>\n";
push @routeFile, " </LineString>\n";
push @routeFile, " <LineString>\n";
push @routeFile, " </Placemark>\n";
push @routeFile, " <tessellate>1</tessellate>\n";
push @routeFile, " <Folder>\n";
push @routeFile, " <coordinates>\n";
push @routeFile, " <name>Orte</name>\n";
push @routeFile, " $track\n";
push @routeFile, " <open>0</open>\n";
push @routeFile, " </coordinates>\n";
push @routeFile, " </LineString>\n";
my $roadBook  = 0;
push @routeFile, " </Placemark>\n";
my $place      = 0;
push @routeFile, " <Folder>\n";
my $touri      = 0;
push @routeFile, " <name>Orte</name>\n";
my $geo        = 0;
push @routeFile, " <open>0</open>\n";
my $lon        = 0;
 
my $lat        = 0;
my $roadBook  = 0;
my $alt        = 0;
my $place      = 0;
my $road      = 0;
my $touri      = 0;
my $kilo      = 0;
my $geo        = 0;
my $lon        = 0;
my $placeName  = "";
my $lat        = 0;
my %placeName  = ();
my $alt        = 0;
my $touriInfo  = "";
my $road      = 0;
my $geoData    = "";
my $kilo      = 0;
my $roadInfo  = "";
 
my $kilometer  = "";
my $placeName  = "";
my %placeName  = ();
foreach my $line (@content) {
my $touriInfo  = "";
my $geoData    = "";
# Last Placemark is finished, Roadbook is finished
my $roadInfo  = "";
if (($roadBook) and ($line =~ /^== .* ==$/)) {
my $kilometer  = "";
 
# Status-Übersicht
foreach my $line (@content) {
if ($touriInfo ne "") { $touri = 1; }
 
if ($roadInfo  ne "") { $road  = 1; }
# Last Placemark is finished, Roadbook is finished
if (($roadBook) and ($line =~ /^== .* ==$/)) {
my $placeNameURL = encodePlaceNameURL($placeName);
 
# Status-Übersicht
if ($placeName{$placeName} > 1) {
if ($touriInfo ne "") { $touri = 1; }
$placeNameURL .= "_$placeName{$placeName}";
if ($roadInfo  ne "") { $road  = 1; }
}
 
my $placeNameURL = encodePlaceNameURL($placeName);
push @routeFile, " <Placemark>\n";
 
push @routeFile, " <name>$placeName</name>\n";
if ($placeName{$placeName} > 1) {
push @routeFile, " <visibility>0</visibility>\n";
$placeNameURL .= "_$placeName{$placeName}";
push @routeFile, " <description>\n";
}
push @routeFile, " <![CDATA[<a id=\"$touri-$road\" href=\"http://radreise-wiki.de/$routeURL#$placeNameURL\">$routeName</a>]]> \n";
 
push @routeFile, " </description>\n";
push @routeFile, " <Placemark>\n";
push @routeFile, " <Point>\n";
push @routeFile, " <name>$placeName</name>\n";
push @routeFile, " <coordinates>\n";
push @routeFile, " <visibility>0</visibility>\n";
push @routeFile, " $lon,$lat,$alt\n";
push @routeFile, " <description>\n";
push @routeFile, " </coordinates>\n";
push @routeFile, " <![CDATA[<a id=\"$touri-$road\" href=\"http://radreise-wiki.de/$routeURL#$placeNameURL\">$routeName</a>]]> \n";
push @routeFile, " </Point>\n";
push @routeFile, " </description>\n";
push @routeFile, " </Placemark>\n";
push @routeFile, " <Point>\n";
push @routeFile, " <coordinates>\n";
$roadBook  = 0;
push @routeFile, " $lon,$lat,$alt\n";
$place    = 0;
push @routeFile, " </coordinates>\n";
$touri    = 0;
push @routeFile, " </Point>\n";
$geo      = 0;
push @routeFile, " </Placemark>\n";
$lon      = 0;
 
$lat      = 0;
$roadBook  = 0;
$alt      = 0;
$place    = 0;
$road      = 0;
$touri    = 0;
$kilo      = 0;
$geo      = 0;
$lon      = 0;
$placeName  = "";
$lat      = 0;
%placeName  = ();
$alt      = 0;
$touriInfo  = "";
$road      = 0;
$geoData    = "";
$kilo      = 0;
$roadInfo  = "";
 
$kilometer  = "";
$placeName  = "";
%placeName  = ();
# Start of Roadbook
$touriInfo  = "";
} elsif ($line =~ /^== Roadbook ==$/) {
$geoData    = "";
$roadInfo  = "";
$roadBook = 1;
$kilometer  = "";
 
# A new Place within the Roadbook
# Start of Roadbook
} elsif ($roadBook and ($line =~ /^=== (.*) ===$/)) {
} elsif ($line =~ /^== Roadbook ==$/) {
 
if ($place and not $kilo) {
$roadBook = 1;
print "  No Kilometers: $routeName :: $placeName\n";
 
#exit;
# A new Place within the Roadbook
}
} elsif ($roadBook and ($line =~ /^=== (.*) ===$/)) {
 
# Save previous place
if ($place and not $kilo) {
if ($place) {
print "  No Kilometers: $routeName :: $placeName\n";
#exit;
# Status-Übersicht
}
if ($touriInfo ne "") { $touri = 1; }
 
if ($roadInfo  ne "") { $road  = 1; }
# Save previous place
if ($place) {
my $placeNameURL = encodePlaceNameURL($placeName);
 
# Status-Übersicht
if ($placeName{$placeName} > 1) {
if ($touriInfo ne "") { $touri = 1; }
$placeNameURL .= "_$placeName{$placeName}";
if ($roadInfo  ne "") { $road  = 1; }
}
 
my $placeNameURL = encodePlaceNameURL($placeName);
push @routeFile, " <Placemark>\n";
 
push @routeFile, " <name>$placeName</name>\n";
if ($placeName{$placeName} > 1) {
push @routeFile, " <visibility>0</visibility>\n";
$placeNameURL .= "_$placeName{$placeName}";
push @routeFile, " <description>\n";
}
push @routeFile, " <![CDATA[<a id=\"$touri-$road\" href=\"http://radreise-wiki.de/$routeURL#$placeNameURL\">$routeName</a>]]> \n";
 
push @routeFile, " </description>\n";
push @routeFile, " <Placemark>\n";
push @routeFile, " <Point>\n";
push @routeFile, " <name>$placeName</name>\n";
push @routeFile, " <coordinates>\n";
push @routeFile, " <visibility>0</visibility>\n";
push @routeFile, " $lon,$lat,$alt\n";
push @routeFile, " <description>\n";
push @routeFile, " </coordinates>\n";
push @routeFile, " <![CDATA[<a id=\"$touri-$road\" href=\"http://radreise-wiki.de/$routeURL#$placeNameURL\">$routeName</a>]]> \n";
push @routeFile, " </Point>\n";
push @routeFile, " </description>\n";
push @routeFile, " </Placemark>\n";
push @routeFile, " <Point>\n";
}
push @routeFile, " <coordinates>\n";
push @routeFile, " $lon,$lat,$alt\n";
$place    = 1;
push @routeFile, " </coordinates>\n";
$touri    = 0;
push @routeFile, " </Point>\n";
$geo      = 0;
push @routeFile, " </Placemark>\n";
$lon      = 0;
}
$lat      = 0;
 
$alt      = 0;
$place    = 1;
$road      = 0;
$touri    = 0;
$kilo      = 0;
$geo      = 0;
$lon      = 0;
$placeName  = $1;
$lat      = 0;
if (defined $placeName{$placeName}) {
$alt      = 0;
$placeName{$placeName}++;
$road      = 0;
} else {
$kilo      = 0;
$placeName{$placeName} = 1;
 
}
$placeName  = $1;
if (defined $placeName{$placeName}) {
$touriInfo  = "";
$placeName{$placeName}++;
$geoData    = "";
} else {
$roadInfo  = "";
$placeName{$placeName} = 1;
$kilometer  = "";
}
 
# Geodata within the Placemark
$touriInfo  = "";
} elsif ($place and ($line =~ /^{{Geodaten\|(.*)}}$/)) {
$geoData    = "";
$roadInfo  = "";
$geo    = 1;
$kilometer  = "";
$geoData = $1;
 
# Geodata within the Placemark
if ($geoData =~ /^([-]?\d+\.\d+)\|([-]?\d+\.\d+)\|([-]?\d+)\|([^\|]+)$/) {
} elsif ($place and ($line =~ /^\{\{Geodaten\|(.*)}}$/)) {
 
$lat  = $1;
$geo    = 1;
$lon  = $2;
$geoData = $1;
$alt  = $3;
 
if ($geoData =~ /^([-]?\d+\.\d+)\|([-]?\d+\.\d+)\|([-]?\d+)\|([^\|]+)$/) {
} else {
 
print "Error in Geodata: $geoData\n";
$lat  = $1;
exit;
$lon  = $2;
}
$alt  = $3;
 
# Kilometrierung within Placemark
} else {
} elsif ($place and ($line =~ /^{{Kilometrierung\|(.*)}}$/)) {
print "Error in Geodata: $geoData\n";
exit;
if (not $geo) {
}
print "No Coordinates: $routeName :: $placeName\n";
 
exit;
# Kilometrierung within Placemark
}
} elsif ($place and ($line =~ /^\{\{Kilometrierung[Hm6]*\|(.*)}}$/)) {
 
if ($kilo) {
if (not $geo) {
print "  Multiple Kilometers: $routeName :: $placeName\n";
print "No Coordinates: $routeName :: $placeName\n";
#exit;
exit;
}
}
 
$kilo      = 1;
if ($kilo) {
$kilometer = $1;
print "  Multiple Kilometers: $routeName :: $placeName\n";
#exit;
# KilometrierungHm within Placemark
}
} elsif ($place and ($line =~ /^{{KilometrierungHm\|(.*)}}$/)) {
 
$kilo      = 1;
if (not $geo) {
$kilometer = $1;
print "No Coordinates: $routeName :: $placeName\n";
 
exit;
# Empty Line
}
} elsif ($line =~ /^\s*$/) {
 
if ($kilo) {
} elsif ($line =~ /<br style="clear:both" \/>/) {
print "   Multiple Kilometers: $routeName :: $placeName\n";
 
#exit;
} elsif ($line =~ /\[\[Bild/) {
}
 
} elsif ($place and not $geo and not $kilo) {
$kilo     = 1;
 
$kilometer = $1;
$touriInfo .= "$line\n";
 
# Empty Line
} elsif ($place and $geo and not $kilo) {
} elsif ($line =~ /^\s*$/) {
 
$roadInfo .= "$line\n";
} elsif ($line =~ /<br style="clear:both" \/>/) {
 
}
} elsif ($line =~ /\[\[Bild/) {
}
 
} elsif ($place and not $geo and not $kilo) {
&saveRouteFile;
 
$touriInfo .= "$line\n";
print "\n";
 
} elsif ($place and $geo and not $kilo) {
} # if ($type eq "H") {
 
$roadInfo .= "$line\n";
} # foreach my $line (@routeList) {
 
}
print "$counter Files read.\n\n";
}
 
 
&saveRouteFile;
# ==============================
# Generieren des Overview-Files
print "\n";
 
print "Saving Overview.kml File\n";
} # if ($type eq "H") {
 
my  @rfwAllFile = ();
} # foreach my $line (@routeList) {
 
push @rfwAllFile, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
print "$counter Files read.\n\n";
push @rfwAllFile, "<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n";
push @rfwAllFile, "<Document>\n";
push @rfwAllFile, " <name>Radfernwege im Radreise-Wiki</name>\n";
# ==============================
push @rfwAllFile, " <open>1</open>\n";
# Generieren des Overview-Files
 
push @rfwAllFile, " <Folder>\n";
print "Saving Overview.kml File\n";
push @rfwAllFile, " <name>Fluss-Radfernweg</name>\n";
push @rfwAllFile, " <open>0</open>\n";
my  @rfwAllFile = ();
push @rfwAllFile, @Fluss_Radfernweg;
push @rfwAllFile, " </Folder>\n";
push @rfwAllFile, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
 
push @rfwAllFile, "<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n";
push @rfwAllFile, " <Folder>\n";
push @rfwAllFile, "<Document>\n";
push @rfwAllFile, " <name>Anderer Radfernweg</name>\n";
push @rfwAllFile, " <name>Radfernwege im Radreise-Wiki</name>\n";
push @rfwAllFile, " <open>0</open>\n";
push @rfwAllFile, " <open>1</open>\n";
push @rfwAllFile, @Anderer_Radfernweg;
push @rfwAllFile, " </Folder>\n";
push @rfwAllFile, " <Folder>\n";
 
push @rfwAllFile, " <name>Fluss-Radfernweg</name>\n";
push @rfwAllFile, " <Folder>\n";
push @rfwAllFile, " <open>0</open>\n";
push @rfwAllFile, " <name>Querverbindung</name>\n";
push @rfwAllFile, @Fluss_Radfernweg;
push @rfwAllFile, " <open>0</open>\n";
push @rfwAllFile, " </Folder>\n";
push @rfwAllFile, @Querverbindung;
push @rfwAllFile, " </Folder>\n";
push @rfwAllFile, " <Folder>\n";
 
push @rfwAllFile, " <name>Anderer Radfernweg</name>\n";
 
push @rfwAllFile, " <open>0</open>\n";
push @rfwAllFile, " <Folder>\n";
push @rfwAllFile, @Anderer_Radfernweg;
push @rfwAllFile, " <name>Direktverbindung</name>\n";
push @rfwAllFile, " </Folder>\n";
push @rfwAllFile, " <open>0</open>\n";
push @rfwAllFile, @Radweit_Strecke;
push @rfwAllFile, " <Folder>\n";
push @rfwAllFile, " </Folder>\n";
push @rfwAllFile, " <name>Querverbindung</name>\n";
 
push @rfwAllFile, " <open>0</open>\n";
push @rfwAllFile, "</Document>\n";
push @rfwAllFile, @Querverbindung;
push @rfwAllFile, "</kml>\n";
push @rfwAllFile, " </Folder>\n";
 
my $content = "";
foreach my $line (@rfwAllFile) {
push @rfwAllFile, " <Folder>\n";
$content .= $line;
push @rfwAllFile, " <name>Direktverbindung</name>\n";
}
push @rfwAllFile, " <open>0</open>\n";
 
push @rfwAllFile, @Radweit_Strecke;
&saveFileIfChangedOrNew ("$baseDir/", "Overview.kml", encode ($encoding, $content), 1);
push @rfwAllFile, " </Folder>\n";
 
exit(0);
push @rfwAllFile, "</Document>\n";
 
push @rfwAllFile, "</kml>\n";
 
#==========================================================
my $content = "";
#==========================================================
foreach my $line (@rfwAllFile) {
 
$content .= $line;
sub saveRouteFile {
}
 
if ($routeName ne "") {
&saveFileIfChangedOrNew ("$baseDir/", "Overview.kml", encode ($encoding, $content), 1);
 
push @routeFile, " </Folder>\n";
exit(0);
 
my  @routeFileAll = ();
 
#==========================================================
push @routeFileAll, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
#==========================================================
push @routeFileAll, "<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n";
push @routeFileAll, "<Document>\n";
sub saveRouteFile {
 
push @routeFileAll, @routeFile;
if ($routeName ne "") {
 
push @routeFileAll, "</Document>\n";
push @routeFile, " </Folder>\n";
push @routeFileAll, "</kml>\n";
 
my  @routeFileAll = ();
my $content = "";
foreach my $line (@routeFileAll) {
push @routeFileAll, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$content .= $line;
push @routeFileAll, "<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n";
}
push @routeFileAll, "<Document>\n";
 
$content =~ s/id="0-0" //gs;
push @routeFileAll, @routeFile;
$content =~ s/id="0-1" //gs;
$content =~ s/id="1-0" //gs;
push @routeFileAll, "</Document>\n";
$content =~ s/id="1-1" //gs;
push @routeFileAll, "</kml>\n";
 
print encode $encOut, "Saving KML-File  : $routeName\n";
my $content = "";
 
foreach my $line (@routeFileAll) {
&saveFileIfChangedOrNew ("$baseDir/kml/", "$routeFileName.kml", encode ($encoding, $content), 1);
$content .= $line;
 
}
if      ($category eq "Fluss-Radfernweg") {
 
$content =~ s/id="0-0" //gs;
push @Fluss_Radfernweg, " <Folder>\n";
$content =~ s/id="0-1" //gs;
push @Fluss_Radfernweg, @routeFile;
$content =~ s/id="1-0" //gs;
push @Fluss_Radfernweg, " </Folder>\n";
$content =~ s/id="1-1" //gs;
 
} elsif ($category eq "Anderer Radfernweg") {
print encode $encOut, "Saving KML-File  : $routeName\n";
 
push @Anderer_Radfernweg, " <Folder>\n";
&saveFileIfChangedOrNew ("$baseDir/kml/", "$routeFileName.kml", encode ($encoding, $content), 1);
push @Anderer_Radfernweg, @routeFile;
push @Anderer_Radfernweg, " </Folder>\n";
if      ($category eq "Fluss-Radfernweg") {
 
} elsif ($category eq "Querverbindung") {
push @Fluss_Radfernweg, " <Folder>\n";
 
push @Fluss_Radfernweg, @routeFile;
push @Querverbindung, " <Folder>\n";
push @Fluss_Radfernweg, " </Folder>\n";
push @Querverbindung, @routeFile;
push @Querverbindung, " </Folder>\n";
} elsif ($category eq "Anderer Radfernweg") {
 
} elsif ($category eq "Direktverbindung") {
push @Anderer_Radfernweg, " <Folder>\n";
 
push @Anderer_Radfernweg, @routeFile;
push @Radweit_Strecke, " <Folder>\n";
push @Anderer_Radfernweg, " </Folder>\n";
push @Radweit_Strecke, @routeFile;
push @Radweit_Strecke, " </Folder>\n";
} elsif ($category eq "Querverbindung") {
 
} elsif ($category eq "Regionaler Radwanderweg") {
push @Querverbindung, " <Folder>\n";
 
push @Querverbindung, @routeFile;
@Regionaler_Radwanderweg = ();
push @Querverbindung, " </Folder>\n";
 
} elsif ($category eq "Routenplaner Testroute") {
} elsif ($category eq "Direktverbindung") {
 
# do nothing
push @Radweit_Strecke, " <Folder>\n";
 
push @Radweit_Strecke, @routeFile;
} else {
push @Radweit_Strecke, " </Folder>\n";
print "Error: No matching Category: $category\n";
exit;
} elsif ($category eq "Regionaler Radwanderweg") {
}
}
@Regionaler_Radwanderweg = ();
}
</nowiki>
} elsif ($category eq "Routenplaner Testroute") {
 
[[Kategorie: Verwaltungs-Software]]
# do nothing
} else {
print "Error: No matching Category: $category\n";
exit;
}
}
}
</nowiki>

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

Das Perl-Skript overview.pl generiert ein KML-File in dem alle Tracks des Hauptnetzes enthalten sind. Die Tracks werden ohne Punktereduzierung übernommen, sodaß die Datei recht umfangreich wird. Von GoogleEarth kann sie jedoch noch verarbeitet werden. Mit der Overview.kml Datei kann bei neue Strecken gut überprüft werden, ob sie ins Hauptnetz passen und wie die Anschlüsse zu legen sind.

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 $selectedType;

if ($ARGV[0]) {

	$selectedType = $ARGV[0];

} else {

	$selectedType = "H";
}

# ==================
# Reading RouteList

my @routeList;

open FIN, "$baseDir/RouteList.txt" or die "$! : $baseDir/RouteList.txt";
while (<FIN>) { push @routeList, decode $encoding, $_; }
close (FIN);

my @routeFile               = ();
my @Fluss_Radfernweg        = ();
my @Anderer_Radfernweg      = ();
my @Querverbindung          = ();
my @Radweit_Strecke         = ();
my @Regionaler_Radwanderweg = ();

my $routeName;
my $routeFileName;
my $routeURL;
my $category;
my $counter;

foreach my $line (@routeList) {

	(my $dateTXT, my $dateKML, my $type, $routeName) = split " :: ", $line;

	chomp($routeName);

	if ($type eq $selectedType) {

		$counter ++;

		$routeFileName = encode $encAnsi, $routeName;

		$routeURL = encodeRouteNameURL($routeFileName);

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

		print encode $encOut, "Reading Trackfile : $routeFileName\n";

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


		# =================
		# Reading Textfile

		print encode $encOut, "Reading Textfile  : $routeFileName\n";

		my $content;
		open FILE, "$baseDir/text/$routeFileName.txt" or die "$baseDir/text/$routeFileName.txt: $!";
		while (<FILE>) { $content .= decode $encoding, $_; }
		close FILE;


		# =============
		# Check Layout

		if ($content !~ /

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

			/xs) {

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

		$category = $1;

		if (($category eq "Regionaler Radwanderweg") or 
			($category eq "Streckenvorschlag") or
			($category eq "Stadtrundfahrt") or
			($category eq "Radreise") or
			($category eq "Radweit-Strecke") or
			($category eq "Fernroute")
			) {

			$category = "Anderer Radfernweg";
		}

		# =============
		# Get Roadbook

		my $pre_Roadbook;
		my $Roadbook;
		my $post_Roadbook;

		if ( $content =~ /(.*?== Roadbook ==.*?)(===.*?)(\n== .*)/s ) {

			$pre_Roadbook  = $1;
			$Roadbook      = $2;
			$post_Roadbook = $3;

		} else { die "Wrong Roadbook Format\n"; }

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


		# ===============
		# Get Placemarks

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

		@routeFile = ();

		push @routeFile, "	<name>$routeName</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>$routeName 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 id=\"$touri-$road\" href=\"http://radreise-wiki.de/$routeURL#$placeNameURL\">$routeName</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: $routeName :: $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 id=\"$touri-$road\" href=\"http://radreise-wiki.de/$routeURL#$placeNameURL\">$routeName</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  = "";

			# 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;
				}

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

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

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

				$kilo      = 1;
				$kilometer = $1;

			# 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";

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

				$roadInfo .= "$line\n";

			}
		}

		&saveRouteFile;

		print "\n";

	} # if ($type eq "H") {

} # foreach my $line (@routeList) {

print "$counter Files read.\n\n";


# ==============================
# Generieren des Overview-Files

print "Saving Overview.kml File\n";

my   @rfwAllFile = ();

push @rfwAllFile, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
push @rfwAllFile, "<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n";
push @rfwAllFile, "<Document>\n";
push @rfwAllFile, "	<name>Radfernwege im Radreise-Wiki</name>\n";
push @rfwAllFile, "	<open>1</open>\n";

push @rfwAllFile, "	<Folder>\n";
push @rfwAllFile, "		<name>Fluss-Radfernweg</name>\n";
push @rfwAllFile, "		<open>0</open>\n";
push @rfwAllFile, @Fluss_Radfernweg;
push @rfwAllFile, "	</Folder>\n";

push @rfwAllFile, "	<Folder>\n";
push @rfwAllFile, "		<name>Anderer Radfernweg</name>\n";
push @rfwAllFile, "		<open>0</open>\n";
push @rfwAllFile, @Anderer_Radfernweg;
push @rfwAllFile, "	</Folder>\n";

push @rfwAllFile, "	<Folder>\n";
push @rfwAllFile, "		<name>Querverbindung</name>\n";
push @rfwAllFile, "		<open>0</open>\n";
push @rfwAllFile, @Querverbindung;
push @rfwAllFile, "	</Folder>\n";


push @rfwAllFile, "	<Folder>\n";
push @rfwAllFile, "		<name>Direktverbindung</name>\n";
push @rfwAllFile, "		<open>0</open>\n";
push @rfwAllFile, @Radweit_Strecke;
push @rfwAllFile, "	</Folder>\n";

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

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

&saveFileIfChangedOrNew ("$baseDir/", "Overview.kml", encode ($encoding, $content), 1);

exit(0);


#==========================================================
#==========================================================

sub saveRouteFile {

	if ($routeName ne "") {

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

		my   @routeFileAll = ();

		push @routeFileAll, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
		push @routeFileAll, "<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n";
		push @routeFileAll, "<Document>\n";

		push @routeFileAll, @routeFile;

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

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

		$content =~ s/id="0-0" //gs;
		$content =~ s/id="0-1" //gs;
		$content =~ s/id="1-0" //gs;
		$content =~ s/id="1-1" //gs;

		print encode $encOut, "Saving KML-File   : $routeName\n";

		&saveFileIfChangedOrNew ("$baseDir/kml/", "$routeFileName.kml", encode ($encoding, $content), 1);

		if      ($category eq "Fluss-Radfernweg") {

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

		} elsif ($category eq "Anderer Radfernweg") {

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

		} elsif ($category eq "Querverbindung") {

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

		} elsif ($category eq "Direktverbindung") {

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

		} elsif ($category eq "Regionaler Radwanderweg") {

			@Regionaler_Radwanderweg = ();

		} elsif ($category eq "Routenplaner Testroute") {

			# do nothing

		} else {
			print "Error: No matching Category: $category\n";
			exit;
		}
	}
}