#!/usr/bin/perl
#-------------------------------------------------------------------------------
#	Erzeuge das Raster der TK25 als GPX
#-------------------------------------------------------------------------------
#	Lizensiert unter der WTFPL-Lizenz		http://www.wtfpl.net/
#-------------------------------------------------------------------------------

use strict;

my $LON_BASE =  6.0;	# Start-Grad
my $LON_STEP =  1/6.0;	# Schritt je Linie

my $LAT_BASE = 56.0;	# Start-Grad
my $LAT_STEP = -0.1;	# Schritt je Linie

my $X_FROM =  2;
my $X_UPTO = 58;

my $Y_FROM =  0;
my $Y_UPTO = 96;

#-------------------------------------------------------------------------------
#	Header
#-------------------------------------------------------------------------------

print <<"EOT";
<?xml version="1.0" encoding="utf-8"?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" creator="tk.pl">
EOT

#-------------------------------------------------------------------------------
#	Senkrechte Linien
#-------------------------------------------------------------------------------

foreach my $x ($X_FROM .. $X_UPTO) {

	my $lon = sprintf("%.5f", $LON_BASE + ($x      - $X_FROM) * $LON_STEP);
	my $lat1= sprintf("%.5f", $LAT_BASE                                  );
	my $lat2= sprintf("%.5f", $LAT_BASE + ($Y_UPTO - $Y_FROM) * $LAT_STEP);

	print <<"EOT";
<trk>
<name>x $x</name>
<trkseg>
<trkpt lat="${lat1}" lon="${lon}" />
<trkpt lat="${lat2}" lon="${lon}" />
</trkseg>
</trk>
EOT
}

#-------------------------------------------------------------------------------
#	Waagrechte Linien
#-------------------------------------------------------------------------------

foreach my $y ($Y_FROM .. $Y_UPTO) {

	my $lat = sprintf("%.5f", $LAT_BASE + ($y      - $Y_FROM) * $LAT_STEP);
	my $lon1= sprintf("%.5f", $LON_BASE                                  );
	my $lon2= sprintf("%.5f", $LON_BASE + ($X_UPTO - $X_FROM) * $LON_STEP);

	print <<"EOT";
<trk>
<name>y $y</name>
<trkseg>
<trkpt lat="${lat}" lon="${lon1}" />
<trkpt lat="${lat}" lon="${lon2}" />
</trkseg>
</trk>
EOT
}

#-------------------------------------------------------------------------------
#	Footer
#-------------------------------------------------------------------------------

print <<"EOT";
</gpx>
EOT

exit 0;

#-------------------------------------------------------------------------------
#	Erzeuge das Raster der TK25 als GPX
#-------------------------------------------------------------------------------
__END__
