1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
| my($fichier,@emprises)=@_; # @emprises au format XYZ en sec d'arc décimales
# Premiere chose à faire: definir l'emprise globale de 0 à x.
# Donc trouver XMIN et YMIN et XMAX et YMAX
my ($xmin,$xmax,$ymin,$ymax)=(-1,-1,-1,-1);
foreach my $ligne (@emprises) {
if ($ligne =~ m/(-?\d+)(\.\d+)?\s(-?\d+)(\.\d+)?.*/) {
my $x = "$1$2";
my $y = "$3$4";
$xmin=$x if (($xmin == -1) || ($xmin > $x));
$ymin=$y if (($ymin == -1) || ($ymin > $y));
$xmax=$x if (($xmax == -1) || ($xmax < $x));
$ymax=$y if (($ymax == -1) || ($ymax < $y));
} # Fin if
} # Fin foreach
#On fait une premiere mise en forme d'emprises pour tout passer en positif
# if (($xmin < 0) || ($ymin < 0)) {
my $difference_x = 0-$xmin;
my $difference_y = 0-$ymin;
print "Diff X: $difference_x\nY: $difference_y\n";
foreach my $ligne (@emprises) {
if ($ligne =~ m/(-?\d+)(\.\d+)?\s(-?\d+)(\.\d+)?.*/) {
my $x = "$1$2";
my $y = "$3$4";
$x += $difference_x;
$y += $difference_y;
$ligne = "$x $y\n";
print $ligne;
} # Fin if
} # Fin de foreach
$xmin = 0;
$ymin = 0;
$xmax += $difference_x;
$ymax += $difference_y;
# } # Fin if
# On ramene maintenant l'ensemble à 800*600 pixels (1 seconde=1pixel actuellement)
print "Resolution : $res_x * $res_y\n";
my $coef_homothetie_x = $xmax / $res_x;
my $coef_homothetie_y = $ymax / $res_y;
if (($coef_homothetie_x > 1) || ($coef_homothetie_y > 1)) { # Il faut reduire par le coef le plus grand
my $coef;
$coef = $coef_homothetie_x if ($coef_homothetie_x > $coef_homothetie_y);
$coef = $coef_homothetie_y if ($coef_homothetie_x <= $coef_homothetie_y);
#On modifie les x/y des emprises par le coef
print "Reduction coef $coef...\n";
$xmax = 0;
$ymax=0;
foreach my $ligne (@emprises) {
if ($ligne =~ m/(-?\d+)(\.\d+)?\s(-?\d+)(\.\d+)?.*/) {
my $x = "$1$2";
my $y = "$3$4";
$x = ($x / $coef) if ($x >0);
$y = ($y / $coef) if ($y >0);
$xmin=$x if (($xmin == -1) || ($xmin > $x));
$ymin=$y if (($ymin == -1) || ($ymin > $y));
$xmax=$x if (($xmax == -1) || ($xmax < $x));
$ymax=$y if (($ymax == -1) || ($ymax < $y));
$ligne = "$x $y\n";
print $ligne;
} # Fin if
} # Fin de foreach
} # FIn if
print "X Varie de $xmin à $xmax\nY de $ymin à $ymax\n";
if ($xmax * $ymax < 100) { # Si moins de 100 pixels², probleme!
&afficher_erreur("\aERREUR pendant la creation du graphique. Taille image incohérente.");
exit 1;
} # Fin if
# On peut créer l'image...
my $image = Imager->new(xsize =>$xmax, ysize => $ymax);
# On crée maintenant les emprises en polygones des cartes
my @polygone;
my $fill = Imager::Fill->new(hatch=>'dots4', fg=>'red', bg=>'white');
foreach my $ligne (@emprises) { # Tant qu'on a des lignes.. on les lit!
if ($ligne =~ m/(-?\d+)(\.\d+)?\s(-?\d+)(\.\d+)?.*/) {
my $x = "$1$2";
my $y = "$3$4";
push @polygone, [$x,$y];
} # Fin if
elsif ($ligne eq "\n") { # Fin du polygnone
$image->polyline(points => \@polygone, color => 'red', fill => $fill );
@polygone=();
} # Fin elsif
} # Fin de foreach
$image->write(file=>'tutorial1.bmp')
or die 'Cannot save tutorial1.bmp: ', $image->errstr; |
Partager