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

Aus Radreise-Wiki
 
(4 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
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.
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:'''


  <nowiki>
  <nowiki>
use strict;
use strict;
 
# Encoding Stuff
use Encode qw(encode decode);
use Encode qw(encode decode);
 
my $encUTF8 = 'utf-8';  # UTF-8
# Default Settings
my $encDOS  = 'cp850' ; # DOS Fenster
push @INC, '.';
my $encAnsi = 'cp1252'; # Windows Ansi
require "ini.pl";
my $encOut = $encDOS;
my ($baseDir, $outDir, $username, $password, $encoding, $encAnsi, $encOut) = getIni();
use URI::Escape qw( uri_escape_utf8 );
 
use CGI; my $cgi = new CGI;
my $selectedType;
 
# Default Directories
if ($ARGV[0]) {
 
require "ini.pl";
$selectedType = $ARGV[0];
my ($baseDir, $outDir, $username, $password) = getIni();
 
} else {
 
my $selectedType;
$selectedType = "H";
}
if ($ARGV[0]) {
 
# ==================
$selectedType = $ARGV[0];
# Reading RouteList
 
} else {
my @routeList;
 
$selectedType = "H";
open FIN, "$baseDir/RouteList.txt" or die "$! : $baseDir/RouteList.txt";
}
while (<FIN>) { push @routeList, decode $encoding, $_; }
close (FIN);
# ==================
 
# Reading RouteList
my @routeFile              = ();
my @Fluss_Radfernweg        = ();
my @routeList;
my @Anderer_Radfernweg      = ();
my @Querverbindung          = ();
open FIN, "$baseDir/RouteList.txt" or die "$! : $baseDir/RouteList.txt";
my @Radweit_Strecke        = ();
while (<FIN>) { push @routeList, decode $encUTF8, $_; }
my @Regionaler_Radwanderweg = ();
close (FIN);
 
my $routeName;
my @routeFile              = ();
my $routeFileName;
my @Fluss_Radfernweg        = ();
my $routeURL;
my @Anderer_Radfernweg      = ();
my $category;
my @Querverbindung          = ();
my $counter;
my @Radweit_Strecke        = ();
 
my @Regionaler_Radwanderweg = ();
foreach my $line (@routeList) {
 
my $routeName;
(my $dateTXT, my $dateKML, my $type, $routeName) = split " :: ", $line;
my $routeFileName;
 
my $routeURL;
chomp($routeName);
my $category;
 
my $counter;
if ($type eq $selectedType) {
 
foreach my $line (@routeList) {
$counter ++;
 
(my $dateTXT, my $dateKML, my $type, $routeName) = split " :: ", $line;
$routeFileName = encode $encAnsi, $routeName;
 
chomp($routeName);
$routeURL = encodeRouteNameURL($routeFileName);
 
if ($type eq $selectedType) {
# ==================
# Reading Trackfile
$counter ++;
 
print encode $encOut, "Reading Trackfile : $routeFileName\n";
$routeFileName = encode $encAnsi, $routeName;
 
open FIN, "$baseDir/tracks/$routeFileName.txt" or die "$! : $baseDir/tracks/$routeFileName.txt";
my $urlstring  = uri_escape_utf8($routeFileName);
my $track = <FIN>;
$urlstring =~ s/%20/\_/g;
close (FIN);
$urlstring =~ s/\(/%28/g;
 
$urlstring =~ s/\)/%29/g;
 
$urlstring =~ s/\'/%27/g;
# =================
$routeURL = $urlstring;
# Reading Textfile
 
# ==================
print encode $encOut, "Reading Textfile  : $routeFileName\n";
# Reading Trackfile
 
my $content;
print encode $encDOS, "Reading Trackfile : $routeFileName\n";
open FILE, "$baseDir/text/$routeFileName.txt" or die "$baseDir/text/$routeFileName.txt: $!";
while (<FILE>) { $content .= decode $encoding, $_; }
open FIN, "$baseDir/tracks/$routeFileName.txt" or die "$! : $baseDir/tracks/$routeFileName.txt";
close FILE;
my $track = <FIN>;
 
close (FIN);
 
# =============
# Check Layout
# =================
 
# Reading Textfile
if ($content !~ /
 
print encode $encDOS, "Reading Textfile  : $routeFileName\n";
\{\{TOC_Radfernweg}}\n
.*
my $content;
\n==\ Roadbook\ ==\n
open FILE, "$baseDir/text/$routeFileName.txt" or die "$baseDir/text/$routeFileName.txt: $!";
.*
while (<FILE>) { $content .= decode $encUTF8, $_; }
\n==\ GPS-Tracks\ ==\n
close FILE;
.*
\[\[Kategorie:\s*(
Fluss-Radfernweg|
# =============
Anderer\ Radfernweg|
# Check Layout
Querverbindung|
Radweit-Strecke|
if ($content !~ /
Direktverbindung|
Regionaler\ Radwanderweg|
{{TOC_Radfernweg}}\n
Routenplaner\ Testroute|
.*
Radreise|
\n==\ Roadbook\ ==\n
Fernroute|
.*
Streckenvorschlag|
\n==\ GPS-Tracks\ ==\n
Stadtrundfahrt
.*
)
\[\[Kategorie:\s*(
 
Fluss-Radfernweg|
/xs) {
Anderer\ Radfernweg|
 
Querverbindung|
print encode $encOut, "Chapters in $routeName are not correct!\n";  
Direktverbindung|
exit(1);
Regionaler\ Radwanderweg|
}
Routenplaner\ Testroute|
 
Fernroute|
$category = $1;
Streckenvorschlag|
 
Stadtrundfahrt
if (($category eq "Regionaler Radwanderweg") or  
)\]\]
($category eq "Streckenvorschlag") or
($category eq "Stadtrundfahrt") or
/xs) {
($category eq "Radreise") or
($category eq "Radweit-Strecke") or
print encode $encDOS, "Chapters in $routeName are not correct!\n";  
($category eq "Fernroute")
exit(1);
) {
}
 
$category = "Anderer Radfernweg";
$category = $1;
}
 
if (($category eq "Regionaler Radwanderweg") or  
# =============
($category eq "Streckenvorschlag") or
# Get Roadbook
($category eq "Stadtrundfahrt") or
 
($category eq "Fernroute")
my $pre_Roadbook;
) {
my $Roadbook;
my $post_Roadbook;
$category = "Anderer Radfernweg";
 
}
if ( $content =~ /(.*?== Roadbook ==.*?)(===.*?)(\n== .*)/s ) {
 
# =============
$pre_Roadbook  = $1;
# Get Roadbook
$Roadbook      = $2;
$post_Roadbook = $3;
my $pre_Roadbook;
 
my $Roadbook;
} else { die "Wrong Roadbook Format\n"; }
my $post_Roadbook;
 
my @Roadbook = split "\n", $Roadbook;
if ( $content =~ /(.*?== Roadbook ==.*?)(===.*?)(\n== .*)/s ) {
 
 
$pre_Roadbook  = $1;
# ===============
$Roadbook      = $2;
# Get Placemarks
$post_Roadbook = $3;
 
my @content  = split "\n", $content;
} else { die "Wrong Roadbook Format\n"; }
 
@routeFile = ();
my @Roadbook = split "\n", $Roadbook;
 
push @routeFile, " <name>$routeName</name>\n";
push @routeFile, " <Metadata>\n";
# ===============
push @routeFile, " <![CDATA[<!--$routeURL-->]]>\n";
# Get Placemarks
push @routeFile, " </Metadata>\n";
push @routeFile, " <open>0</open>\n";
my @content  = split "\n", $content;
push @routeFile, " <Placemark>\n";
push @routeFile, " <name>$routeName GPS-Track</name>\n";
@routeFile = ();
push @routeFile, " <description>\n";
push @routeFile, " <![CDATA[<a href=\"http://radreise-wiki.de/$routeURL\">Wiki</a>]]> \n";
push @routeFile, " <name>$routeName</name>\n";
push @routeFile, " </description>\n";
push @routeFile, " <Metadata>\n";
push @routeFile, " <Style>\n";
push @routeFile, " <![CDATA[<!--$routeURL-->]]>\n";
push @routeFile, " <LineStyle>\n";
push @routeFile, " </Metadata>\n";
push @routeFile, " <color>ffff00ff</color>\n";
push @routeFile, " <open>0</open>\n";
push @routeFile, " <width>2</width>\n";
push @routeFile, " <Placemark>\n";
push @routeFile, " </LineStyle>\n";
push @routeFile, " <name>$routeName GPS-Track</name>\n";
push @routeFile, " </Style>\n";
push @routeFile, " <description>\n";
push @routeFile, " <LineString>\n";
push @routeFile, " <![CDATA[<a href=\"http://radreise-wiki.de/$routeURL\">Wiki</a>]]> \n";
push @routeFile, " <tessellate>1</tessellate>\n";
push @routeFile, " </description>\n";
push @routeFile, " <coordinates>\n";
push @routeFile, " <Style>\n";
push @routeFile, " $track\n";
push @routeFile, " <LineStyle>\n";
push @routeFile, " </coordinates>\n";
push @routeFile, " <color>ffff00ff</color>\n";
push @routeFile, " </LineString>\n";
push @routeFile, " <width>2</width>\n";
push @routeFile, " </Placemark>\n";
push @routeFile, " </LineStyle>\n";
push @routeFile, " <Folder>\n";
push @routeFile, " </Style>\n";
push @routeFile, " <name>Orte</name>\n";
push @routeFile, " <LineString>\n";
push @routeFile, " <open>0</open>\n";
push @routeFile, " <tessellate>1</tessellate>\n";
 
push @routeFile, " <coordinates>\n";
my $roadBook  = 0;
push @routeFile, " $track\n";
my $place      = 0;
push @routeFile, " </coordinates>\n";
my $touri      = 0;
push @routeFile, " </LineString>\n";
my $geo        = 0;
push @routeFile, " </Placemark>\n";
my $lon        = 0;
push @routeFile, " <Folder>\n";
my $lat        = 0;
push @routeFile, " <name>Orte</name>\n";
my $alt        = 0;
push @routeFile, " <open>0</open>\n";
my $road      = 0;
my $kilo      = 0;
my $roadBook  = 0;
 
my $place      = 0;
my $placeName  = "";
my $touri      = 0;
my %placeName  = ();
my $geo        = 0;
my $touriInfo  = "";
my $lon        = 0;
my $geoData    = "";
my $lat        = 0;
my $roadInfo  = "";
my $alt        = 0;
my $kilometer  = "";
my $road      = 0;
 
my $kilo      = 0;
foreach my $line (@content) {
 
my $placeName  = "";
# Last Placemark is finished, Roadbook is finished
my %placeName  = ();
if (($roadBook) and ($line =~ /^== .* ==$/)) {
my $touriInfo  = "";
 
my $geoData    = "";
# Status-Übersicht
my $roadInfo  = "";
if ($touriInfo ne "") { $touri = 1; }
my $kilometer  = "";
if ($roadInfo  ne "") { $road  = 1; }
 
foreach my $line (@content) {
my $placeNameURL = encodePlaceNameURL($placeName);
 
# Last Placemark is finished, Roadbook is finished
if ($placeName{$placeName} > 1) {
if (($roadBook) and ($line =~ /^== .* ==$/)) {
$placeNameURL .= "_$placeName{$placeName}";
}
# Status-Übersicht
 
if ($touriInfo ne "") { $touri = 1; }
push @routeFile, " <Placemark>\n";
if ($roadInfo  ne "") { $road  = 1; }
push @routeFile, " <name>$placeName</name>\n";
push @routeFile, " <visibility>0</visibility>\n";
my $placeNameURL = $cgi->escape($placeName);
push @routeFile, " <description>\n";
$placeNameURL    =~ s/\%20/\_/g;
push @routeFile, " <![CDATA[<a id=\"$touri-$road\" href=\"http://radreise-wiki.de/$routeURL#$placeNameURL\">$routeName</a>]]> \n";
$placeNameURL    =~ s/\%/\./g;
push @routeFile, " </description>\n";
if ($placeName{$placeName} > 1) {
push @routeFile, " <Point>\n";
$placeNameURL .= "_$placeName{$placeName}";
push @routeFile, " <coordinates>\n";
}
push @routeFile, " $lon,$lat,$alt\n";
push @routeFile, " </coordinates>\n";
push @routeFile, " <Placemark>\n";
push @routeFile, " </Point>\n";
push @routeFile, " <name>$placeName</name>\n";
push @routeFile, " </Placemark>\n";
push @routeFile, " <visibility>0</visibility>\n";
 
push @routeFile, " <description>\n";
$roadBook  = 0;
push @routeFile, " <![CDATA[<a id=\"$touri-$road\" href=\"http://radreise-wiki.de/$routeURL#$placeNameURL\">$routeName</a>]]> \n";
$place    = 0;
push @routeFile, " </description>\n";
$touri    = 0;
push @routeFile, " <Point>\n";
$geo      = 0;
push @routeFile, " <coordinates>\n";
$lon      = 0;
push @routeFile, " $lon,$lat,$alt\n";
$lat      = 0;
push @routeFile, " </coordinates>\n";
$alt      = 0;
push @routeFile, " </Point>\n";
$road      = 0;
push @routeFile, " </Placemark>\n";
$kilo      = 0;
 
$roadBook  = 0;
$placeName  = "";
$place    = 0;
%placeName  = ();
$touri    = 0;
$touriInfo  = "";
$geo      = 0;
$geoData    = "";
$lon      = 0;
$roadInfo  = "";
$lat      = 0;
$kilometer  = "";
$alt      = 0;
 
$road      = 0;
# Start of Roadbook
$kilo      = 0;
} elsif ($line =~ /^== Roadbook ==$/) {
 
$placeName  = "";
$roadBook = 1;
%placeName  = ();
 
$touriInfo  = "";
# A new Place within the Roadbook
$geoData    = "";
} elsif ($roadBook and ($line =~ /^=== (.*) ===$/)) {
$roadInfo  = "";
 
$kilometer  = "";
if ($place and not $kilo) {
print "  No Kilometers: $routeName :: $placeName\n";
# Start of Roadbook
#exit;
} elsif ($line =~ /^== Roadbook ==$/) {
}
 
$roadBook = 1;
# Save previous place
if ($place) {
# A new Place within the Roadbook
 
} elsif ($roadBook and ($line =~ /^=== (.*) ===$/)) {
# Status-Übersicht
if ($touriInfo ne "") { $touri = 1; }
if ($place and not $kilo) {
if ($roadInfo  ne "") { $road  = 1; }
print "  No Kilometers: $routeName :: $placeName\n";
 
#exit;
my $placeNameURL = encodePlaceNameURL($placeName);
}
 
if ($placeName{$placeName} > 1) {
# Save previous place
$placeNameURL .= "_$placeName{$placeName}";
if ($place) {
}
 
# Status-Übersicht
push @routeFile, " <Placemark>\n";
if ($touriInfo ne "") { $touri = 1; }
push @routeFile, " <name>$placeName</name>\n";
if ($roadInfo  ne "") { $road  = 1; }
push @routeFile, " <visibility>0</visibility>\n";
push @routeFile, " <description>\n";
my $placeNameURL = $cgi->escape($placeName);
push @routeFile, " <![CDATA[<a id=\"$touri-$road\" href=\"http://radreise-wiki.de/$routeURL#$placeNameURL\">$routeName</a>]]> \n";
$placeNameURL    =~ s/\%20/\_/g;
push @routeFile, " </description>\n";
$placeNameURL    =~ s/\%/\./g;
push @routeFile, " <Point>\n";
if ($placeName{$placeName} > 1) {
push @routeFile, " <coordinates>\n";
$placeNameURL .= "_$placeName{$placeName}";
push @routeFile, " $lon,$lat,$alt\n";
}
push @routeFile, " </coordinates>\n";
push @routeFile, " </Point>\n";
push @routeFile, " <Placemark>\n";
push @routeFile, " </Placemark>\n";
push @routeFile, " <name>$placeName</name>\n";
}
push @routeFile, " <visibility>0</visibility>\n";
 
push @routeFile, " <description>\n";
$place    = 1;
push @routeFile, " <![CDATA[<a id=\"$touri-$road\" href=\"http://radreise-wiki.de/$routeURL#$placeNameURL\">$routeName</a>]]> \n";
$touri    = 0;
push @routeFile, " </description>\n";
$geo      = 0;
push @routeFile, " <Point>\n";
$lon      = 0;
push @routeFile, " <coordinates>\n";
$lat      = 0;
push @routeFile, " $lon,$lat,$alt\n";
$alt      = 0;
push @routeFile, " </coordinates>\n";
$road      = 0;
push @routeFile, " </Point>\n";
$kilo      = 0;
push @routeFile, " </Placemark>\n";
 
}
$placeName  = $1;
if (defined $placeName{$placeName}) {
$place    = 1;
$placeName{$placeName}++;
$touri    = 0;
} else {
$geo      = 0;
$placeName{$placeName} = 1;
$lon      = 0;
}
$lat      = 0;
 
$alt      = 0;
$touriInfo  = "";
$road      = 0;
$geoData    = "";
$kilo      = 0;
$roadInfo  = "";
$kilometer  = "";
$placeName  = $1;
 
if (defined $placeName{$placeName}) {
# Geodata within the Placemark
$placeName{$placeName}++;
} elsif ($place and ($line =~ /^\{\{Geodaten\|(.*)}}$/)) {
} else {
 
$placeName{$placeName} = 1;
$geo    = 1;
}
$geoData = $1;
 
$touriInfo  = "";
if ($geoData =~ /^([-]?\d+\.\d+)\|([-]?\d+\.\d+)\|([-]?\d+)\|([^\|]+)$/) {
$geoData    = "";
 
$roadInfo  = "";
$lat  = $1;
$kilometer  = "";
$lon  = $2;
$alt  = $3;
# Geodata within the Placemark
 
} elsif ($place and ($line =~ /^{{Geodaten\|(.*)}}$/)) {
} else {
print "Error in Geodata: $geoData\n";
$geo    = 1;
exit;
$geoData = $1;
}
 
if ($geoData =~ /^([-]?\d+\.\d+)\|([-]?\d+\.\d+)\|([-]?\d+)\|([^\|]+)$/) {
# Kilometrierung within Placemark
} elsif ($place and ($line =~ /^\{\{Kilometrierung[Hm6]*\|(.*)}}$/)) {
$lat  = $1;
 
$lon  = $2;
if (not $geo) {
$alt  = $3;
print "No Coordinates: $routeName :: $placeName\n";
exit;
} else {
}
print "Error in Geodata: $geoData\n";
 
exit;
if ($kilo) {
}
print "  Multiple Kilometers: $routeName :: $placeName\n";
#exit;
# Kilometrierung within Placemark
}
} elsif ($place and ($line =~ /^{{Kilometrierung\|(.*)}}$/)) {
 
$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";
 
# KilometrierungHm within Placemark
} elsif ($place and $geo and not $kilo) {
} elsif ($place and ($line =~ /^{{KilometrierungHm\|(.*)}}$/)) {
 
$roadInfo .= "$line\n";
if (not $geo) {
 
print "No Coordinates: $routeName :: $placeName\n";
}
exit;
}
}
 
&saveRouteFile;
if ($kilo) {
 
print "   Multiple Kilometers: $routeName :: $placeName\n";
print "\n";
#exit;
 
}
} # if ($type eq "H") {
 
$kilo     = 1;
} # foreach my $line (@routeList) {
$kilometer = $1;
 
print "$counter Files read.\n\n";
# Empty Line
 
} elsif ($line =~ /^\s*$/) {
 
# ==============================
} elsif ($line =~ /<br style="clear:both" \/>/) {
# Generieren des Overview-Files
 
} elsif ($line =~ /\[\[Bild/) {
print "Saving Overview.kml File\n";
 
} elsif ($place and not $geo and not $kilo) {
my  @rfwAllFile = ();
 
$touriInfo .= "$line\n";
push @rfwAllFile, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
push @rfwAllFile, "<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n";
} elsif ($place and $geo and not $kilo) {
push @rfwAllFile, "<Document>\n";
push @rfwAllFile, " <name>Radfernwege im Radreise-Wiki</name>\n";
$roadInfo .= "$line\n";
push @rfwAllFile, " <open>1</open>\n";
 
}
push @rfwAllFile, " <Folder>\n";
}
push @rfwAllFile, " <name>Fluss-Radfernweg</name>\n";
push @rfwAllFile, " <open>0</open>\n";
&saveRouteFile;
push @rfwAllFile, @Fluss_Radfernweg;
push @rfwAllFile, " </Folder>\n";
print "\n";
 
push @rfwAllFile, " <Folder>\n";
} # if ($type eq "H") {
push @rfwAllFile, " <name>Anderer Radfernweg</name>\n";
push @rfwAllFile, " <open>0</open>\n";
} # foreach my $line (@routeList) {
push @rfwAllFile, @Anderer_Radfernweg;
push @rfwAllFile, " </Folder>\n";
print "$counter Files read.\n\n";
 
push @rfwAllFile, " <Folder>\n";
push @rfwAllFile, " <name>Querverbindung</name>\n";
# ==============================
push @rfwAllFile, " <open>0</open>\n";
# Generieren des Overview-Files
push @rfwAllFile, @Querverbindung;
push @rfwAllFile, " </Folder>\n";
print "Saving Overview.kml File\n";
 
 
my  @rfwAllFile = ();
push @rfwAllFile, " <Folder>\n";
push @rfwAllFile, " <name>Direktverbindung</name>\n";
push @rfwAllFile, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
push @rfwAllFile, " <open>0</open>\n";
push @rfwAllFile, "<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n";
push @rfwAllFile, @Radweit_Strecke;
push @rfwAllFile, "<Document>\n";
push @rfwAllFile, " </Folder>\n";
push @rfwAllFile, " <name>Radfernwege im Radreise-Wiki</name>\n";
 
push @rfwAllFile, " <open>1</open>\n";
push @rfwAllFile, "</Document>\n";
push @rfwAllFile, "</kml>\n";
push @rfwAllFile, " <Folder>\n";
 
push @rfwAllFile, " <name>Fluss-Radfernweg</name>\n";
my $content = "";
push @rfwAllFile, " <open>0</open>\n";
foreach my $line (@rfwAllFile) {
push @rfwAllFile, @Fluss_Radfernweg;
$content .= $line;
push @rfwAllFile, " </Folder>\n";
}
 
push @rfwAllFile, " <Folder>\n";
&saveFileIfChangedOrNew ("$baseDir/", "Overview.kml", encode ($encoding, $content), 1);
push @rfwAllFile, " <name>Anderer Radfernweg</name>\n";
 
push @rfwAllFile, " <open>0</open>\n";
exit(0);
push @rfwAllFile, @Anderer_Radfernweg;
 
push @rfwAllFile, " </Folder>\n";
 
#==========================================================
push @rfwAllFile, " <Folder>\n";
#==========================================================
push @rfwAllFile, " <name>Querverbindung</name>\n";
 
push @rfwAllFile, " <open>0</open>\n";
sub saveRouteFile {
push @rfwAllFile, @Querverbindung;
 
push @rfwAllFile, " </Folder>\n";
if ($routeName ne "") {
 
push @routeFile, " </Folder>\n";
push @rfwAllFile, " <Folder>\n";
 
push @rfwAllFile, " <name>Direktverbindung</name>\n";
my  @routeFileAll = ();
push @rfwAllFile, " <open>0</open>\n";
 
push @rfwAllFile, @Radweit_Strecke;
push @routeFileAll, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
push @rfwAllFile, " </Folder>\n";
push @routeFileAll, "<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n";
push @routeFileAll, "<Document>\n";
push @rfwAllFile, "</Document>\n";
 
push @rfwAllFile, "</kml>\n";
push @routeFileAll, @routeFile;
 
my $content = "";
push @routeFileAll, "</Document>\n";
foreach my $line (@rfwAllFile) {
push @routeFileAll, "</kml>\n";
$content .= $line;
 
}
my $content = "";
foreach my $line (@routeFileAll) {
&saveFileIfChangedOrNew ("$baseDir/", "Overview.kml", encode ($encUTF8, $content), 1);
$content .= $line;
}
exit(0);
 
$content =~ s/id="0-0" //gs;
$content =~ s/id="0-1" //gs;
#==========================================================
$content =~ s/id="1-0" //gs;
#==========================================================
$content =~ s/id="1-1" //gs;
 
sub saveRouteFile {
print encode $encOut, "Saving KML-File  : $routeName\n";
 
if ($routeName ne "") {
&saveFileIfChangedOrNew ("$baseDir/kml/", "$routeFileName.kml", encode ($encoding, $content), 1);
 
push @routeFile, " </Folder>\n";
if      ($category eq "Fluss-Radfernweg") {
 
my  @routeFileAll = ();
push @Fluss_Radfernweg, " <Folder>\n";
push @Fluss_Radfernweg, @routeFile;
push @routeFileAll, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
push @Fluss_Radfernweg, " </Folder>\n";
push @routeFileAll, "<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n";
 
push @routeFileAll, "<Document>\n";
} elsif ($category eq "Anderer Radfernweg") {
 
push @routeFileAll, @routeFile;
push @Anderer_Radfernweg, " <Folder>\n";
push @Anderer_Radfernweg, @routeFile;
push @routeFileAll, "</Document>\n";
push @Anderer_Radfernweg, " </Folder>\n";
push @routeFileAll, "</kml>\n";
 
} elsif ($category eq "Querverbindung") {
my $content = "";
 
foreach my $line (@routeFileAll) {
push @Querverbindung, " <Folder>\n";
$content .= $line;
push @Querverbindung, @routeFile;
}
push @Querverbindung, " </Folder>\n";
 
$content =~ s/id="0-0" //gs;
} elsif ($category eq "Direktverbindung") {
$content =~ s/id="0-1" //gs;
 
$content =~ s/id="1-0" //gs;
push @Radweit_Strecke, " <Folder>\n";
$content =~ s/id="1-1" //gs;
push @Radweit_Strecke, @routeFile;
push @Radweit_Strecke, " </Folder>\n";
print encode $encOut, "Saving KML-File  : $routeName\n";
 
} elsif ($category eq "Regionaler Radwanderweg") {
&saveFileIfChangedOrNew ("$baseDir/kml/", "$routeFileName.kml", encode ($encUTF8, $content), 1);
 
@Regionaler_Radwanderweg = ();
if      ($category eq "Fluss-Radfernweg") {
 
} elsif ($category eq "Routenplaner Testroute") {
push @Fluss_Radfernweg, " <Folder>\n";
 
push @Fluss_Radfernweg, @routeFile;
# do nothing
push @Fluss_Radfernweg, " </Folder>\n";
 
} else {
} elsif ($category eq "Anderer Radfernweg") {
print "Error: No matching Category: $category\n";
exit;
push @Anderer_Radfernweg, " <Folder>\n";
}
push @Anderer_Radfernweg, @routeFile;
}
push @Anderer_Radfernweg, " </Folder>\n";
}
</nowiki>
} elsif ($category eq "Querverbindung") {
 
[[Kategorie: Verwaltungs-Software]]
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;
}
}
}
#==========================================================
use Digest::MD5;
qw(md5_hex);
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
sub saveFileIfChangedOrNew {
(my $path, my $fileName, my $file, my $kmz) = @_;
if (open(FILE, "< $path$fileName")) {
my $md5 = Digest::MD5->new;
while (<FILE>) {
$md5->add($_);
}
close(FILE);
my $md5_old = $md5->hexdigest;
$md5 = Digest::MD5->new;
$md5->add($file);
my $md5_new = $md5->hexdigest;
unless ($md5_old eq $md5_new) {
print encode $encOut, "****************** Overwriting file $fileName ******************\n";
open  FT,"> $path$fileName";
print FT $file;
close FT;
if ($kmz) {
my $zip = Archive::Zip->new();
$zip->addFile("$path$fileName","doc.kml");
$fileName =~ s/\.kml/\.kmz/;
unless ( $zip->writeToFileNamed("$outDir/$fileName") == AZ_OK ) {
  die 'write error';
}
}
}
} else {
print encode $encOut, "****************** Creating new file $fileName ******************\n";
open  FT,"> $path$fileName";
print FT $file;
close FT;
if ($kmz) {
my $zip = Archive::Zip->new();
$zip->addFile("$path$fileName","doc.kml");
$fileName =~ s/\.kml/\.kmz/;
unless ( $zip->writeToFileNamed("$outDir/$fileName") == AZ_OK ) {
  die 'write error';
}
}
}
}
# =========================================================
  </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;
		}
	}
}