A
Anonymous
Guest
Sowohl die 2.77 als auch die 2.78 erzeugen einen Fehler, wenn die Statistik erzeugt werden soll:
Math:
olygon::Calc hab ich schon neu installiert, das sollte es also nicht sein. :/
Code:
Es ist ein Fehler bei der Evaluation von
use Math::Polygon::Calc;
sub loadPolygon
{
my ( $file, $bbox, $poly ) = @_;
# print "opening '$file'\n";
open( FILE, "< $file" ) or die( "Cannot open '$file'\n" );
my @data = <FILE>;
my $line;
close( FILE );
foreach $line (@data)
{
if ( $line =~ m/(\d*\.?\d*),(\d*\.?\d*)/ )
{
my $lat = $1;
my $lon = $2;
push( @$poly, [$lat,$lon] );
}
}
die( "polygon is not closed\n" ) unless( polygon_is_closed( @$poly ) );
@$bbox = polygon_bbox( @$poly );
}
my( @bbox_BE, @poly_BE );
my( @bbox_BR, @poly_BR );
my( @bbox_BW, @poly_BW );
my( @bbox_BY, @poly_BY );
my( @bbox_HB, @poly_HB );
my( @bbox_HE, @poly_HE );
my( @bbox_HH, @poly_HH );
my( @bbox_MV, @poly_MV );
my( @bbox_NI, @poly_NI );
my( @bbox_NW, @poly_NW );
my( @bbox_RP, @poly_RP );
my( @bbox_SH, @poly_SH );
my( @bbox_SL, @poly_SL );
my( @bbox_SN, @poly_SN );
my( @bbox_ST, @poly_ST );
my( @bbox_TH, @poly_TH );
loadPolygon( $directory . "/statistics/states-DE/BE.txt", \@bbox_BE, \@poly_BE );
loadPolygon( $directory . "/statistics/states-DE/BR.txt", \@bbox_BR, \@poly_BR );
loadPolygon( $directory . "/statistics/states-DE/BW.txt", \@bbox_BW, \@poly_BW );
loadPolygon( $directory . "/statistics/states-DE/BY.txt", \@bbox_BY, \@poly_BY );
loadPolygon( $directory . "/statistics/states-DE/HB.txt", \@bbox_HB, \@poly_HB );
loadPolygon( $directory . "/statistics/states-DE/HE.txt", \@bbox_HE, \@poly_HE );
loadPolygon( $directory . "/statistics/states-DE/HH.txt", \@bbox_HH, \@poly_HH );
loadPolygon( $directory . "/statistics/states-DE/MV.txt", \@bbox_MV, \@poly_MV );
loadPolygon( $directory . "/statistics/states-DE/NI.txt", \@bbox_NI, \@poly_NI );
loadPolygon( $directory . "/statistics/states-DE/NW.txt", \@bbox_NW, \@poly_NW );
loadPolygon( $directory . "/statistics/states-DE/RP.txt", \@bbox_RP, \@poly_RP );
loadPolygon( $directory . "/statistics/states-DE/SH.txt", \@bbox_SH, \@poly_SH );
loadPolygon( $directory . "/statistics/states-DE/SL.txt", \@bbox_SL, \@poly_SL );
loadPolygon( $directory . "/statistics/states-DE/SN.txt", \@bbox_SN, \@poly_SN );
loadPolygon( $directory . "/statistics/states-DE/ST.txt", \@bbox_ST, \@poly_ST );
loadPolygon( $directory . "/statistics/states-DE/TH.txt", \@bbox_TH, \@poly_TH );
sub contains
{
my ($lat, $lon, $bbox, $poly ) = @_;
return 0 unless ( $bbox->[0] <= $lat && $lat <= $bbox->[2] && $bbox->[1] <= $lon && $lon <= $bbox->[3] );
return polygon_contains_point( [$lat, $lon], @$poly );
}
sub getStateDE
{
my $lat = shift; die unless (defined $lat);
my $lon = shift; die unless (defined $lon);
if( contains( $lat, $lon, \@bbox_BW, \@poly_BW ) ) { return "BW"; }
if( contains( $lat, $lon, \@bbox_BE, \@poly_BE ) ) { return "BE"; }
if( contains( $lat, $lon, \@bbox_BR, \@poly_BR ) ) { return "BR"; }
if( contains( $lat, $lon, \@bbox_BY, \@poly_BY ) ) { return "BY"; }
if( contains( $lat, $lon, \@bbox_HB, \@poly_HB ) ) { return "HB"; }
if( contains( $lat, $lon, \@bbox_HE, \@poly_HE ) ) { return "HE"; }
if( contains( $lat, $lon, \@bbox_HH, \@poly_HH ) ) { return "HH"; }
if( contains( $lat, $lon, \@bbox_MV, \@poly_MV ) ) { return "MV"; }
if( contains( $lat, $lon, \@bbox_NI, \@poly_NI ) ) { return "NI"; }
if( contains( $lat, $lon, \@bbox_NW, \@poly_NW ) ) { return "NW"; }
if( contains( $lat, $lon, \@bbox_RP, \@poly_RP ) ) { return "RP"; }
if( contains( $lat, $lon, \@bbox_SH, \@poly_SH ) ) { return "SH"; }
if( contains( $lat, $lon, \@bbox_SL, \@poly_SL ) ) { return "SL"; }
if( contains( $lat, $lon, \@bbox_SN, \@poly_SN ) ) { return "SN"; }
if( contains( $lat, $lon, \@bbox_ST, \@poly_ST ) ) { return "ST"; }
if( contains( $lat, $lon, \@bbox_TH, \@poly_TH ) ) { return "TH"; }
return "";
}
sub StatStatesTable {
my(%mapping) = (BR => 'Brandenburg',
BE => 'Berlin',
BW => 'Baden-Württemberg',
BY => 'Bayern',
HB => 'Bremen',
HE => 'Hessen',
HH => 'Hamburg',
MV => 'Mecklenburg-Vorpommern',
NI => 'Niedersachsen',
NW => 'Nordrhein-Westfalen',
RP => 'Rheinland-Pfalz',
SH => 'Schleswig-Holstein',
SL => 'Saarland',
SN => 'Sachsen',
ST => 'Sachsen-Anhalt',
TH => 'Thüringen');
my(%states,$thisstate,$nstatecode,%cache);
%cache = split("\n",suck_in($directory . "/states-DE.cache"));
foreach (keys(%found)) {
if ($found{$_}->{'Country'} eq "Germany") {
$thisstate = $found{$_}->{'State'};
if ($thisstate eq "") {
$thisstate = $mapping{$cache{$_}};
}
if ($thisstate eq "") {
$thisstate =
getStateDE((make_dlat_dlon($found{$_}->{'Coordinates'}))[1,2]);
$cache{$_} = $thisstate if ($thisstate ne "");
$thisstate = $mapping{$thisstate};
}
if ($thisstate eq "") {
$thisstate = 'Keine Zuordnung';
messageED(1,"\nCould not identify a state for '$_'\n",
"\nKonnte kein Bundesland fuer '$_' bestimmen\n");
}
$states{$thisstate}++;
}
}
store_file(join("\n",%cache),$directory . "/states-DE.cache");
return(maketds(0,3,21,5,7,StatCountryCaches("Germany"),pairsort(1,0,%states)));
}
StatStatesTable();
aufgetreten:
Undefined subroutine &main::make_dlat_dlon called at (eval 239) line 126.
Math: