#!/usr/bin/perl use Math::Polygon; use Getopt::Long; my $percentage = 100; my $slope = 0.1; my $same = 0.001; my $help = 0; GetOptions ("percentage=i" => \$percentage, "slope=f" => \$slope, "same=f" => \$same, "help" => \$help) or help(); help() if $help; # first line my $line = <>; print $line; while(1) { my @poly; my $line = <>; last if ($line =~ /^END/); # end of file my $hdr=$line; print STDERR "polygon $line"; while($line = <>) { last if ($line =~ /^END/); # end of poly my ($dummy, $x, $y) = split(/\s+/, $line); push(@poly, [$x, $y]); } my $poly = Math::Polygon->new(@poly); printf STDERR "%d points original\n", $poly->nrPoints; my $max_points = $poly->nrPoints * $percentage / 100; my $simplified = $poly->simplify(max_points => $max_points, same => $same, slope => $slope); printf STDERR "%d points simplified\n", $simplified->nrPoints; next if ($simplified->nrPoints<3); print $hdr; foreach my $pt($simplified->points) { printf " %E %E\n", $pt->[0], $pt->[1]; } print "END\n"; } print "END\n"; sub help { print STDERR <