diff options
author | Guilhem Moulin <guilhem@fripost.org> | 2013-08-17 21:06:17 +0200 |
---|---|---|
committer | Guilhem Moulin <guilhem@fripost.org> | 2013-08-17 21:06:17 +0200 |
commit | 36fd682fbfb4389c3dc1138ee59526f914c919c7 (patch) | |
tree | 4a7271555534250a3ed80b90c53d503e4d9dc88a | |
parent | 43533160c8cfad0f4d6cd7084f32fe950418e244 (diff) |
Ability to use number-only watermarks.
-rwxr-xr-x | mkindex.pl | 32 |
1 files changed, 27 insertions, 5 deletions
@@ -27,9 +27,10 @@ mkindex.pl - Create an index file from a mapset =head1 SYNOPSIS -B<mkindex.pl> [B<-q>] [B<-d>] [B<--rename> I<perlexpr>] [B<-s> I<geometry>] -[B<-r> I<method>] [B<-b> I<border>] [B<-f> I<font>] [B<--s_srs> I<SRS>] -[B<--t_srs> I<SRS>] [-o I<map>] [B<--crop>] I<map> [... I<map>] I<index> +B<mkindex.pl> [B<-q>] [B<-d>] [B<--rename> I<perlexpr>] [B<-n> I<file>] +[B<-s> I<geometry>] [B<-r> I<method>] [B<-b> I<border>] [B<-f> I<font>] +[B<--s_srs> I<SRS>] [B<--t_srs> I<SRS>] [-o I<map>] [B<--crop>] I<map> +[... I<map>] I<index> B<mkindex.pl> B<--man> @@ -65,6 +66,14 @@ to each filename), to what should be displayed on the final index. The default is 's/\.[^.]+$//' that is, only the file extension is stripped away. See the B<EXAMPLES> section for other examples. +=item B<-n> I<file>, B<--numeric>=I<file> + +Instead of annoting the index with the map names, use an increasing +counter starting from 1, and write the mapping I<num: text> in I<file>, +where I<text> is a map name massaged with I<perlexpr> (see B<--rename>). +If I<file> is a single hyphen-minus (I<->), the mapping is written to +the standard output. + =item B<-s> I<width>xI<height>, B<--size=>I<width>xI<height> The size of the output index (default: 1024x0). If I<width> or I<height> @@ -236,6 +245,7 @@ GetOptions( "q|quiet" => sub { delete $config{progress} } , "rename=s" => sub { pod2usage(2) unless $_[1] =~ /^s(.).+\1[ixgcadlu]*$/; $config{rename} = $_[1] } + , "n|numeric=s" => \$config{numeric} , "s|size=s" => sub { pod2usage(2) unless $_[1] =~ /^(\d+)x(\d+)$/; $config{outsize} = [ $1, $2 ]; } @@ -266,7 +276,6 @@ GetOptions( "q|quiet" => sub { delete $config{progress} } , "man" => sub { pod2usage(-exitstatus => 0, -verbose => 2) } ) or pod2usage(2); -# TODO: -n|--numeric: put numbers instead of text # TODO: when the input is RGB (not RGBA), we want add an alpha channel # but keep the nodata value as matte within the map bounds. # This seems to be possible with a clever use of @@ -277,6 +286,12 @@ pod2usage(2) unless $#ARGV > 0; my $index = pop; my @mapset = map {{ filename => $_ }} @ARGV; $config{fontcolor} //= $config{bordercolor}; +if ($config{numeric}) { + $config{numeric_format} = "%.".(length $#mapset)."d"; + open my $fh, '>', $config{numeric} + or die "Error: Can't open '".$config{numeric}."': $!"; + $config{numeric} = $fh; +} &debug( "Using mapset:", map {" - ".$_->{filename}} @mapset ); if ($config{overviews}) { @@ -361,6 +376,7 @@ $config{t_srs} //= $config{s_srs} // $s_srs; # Store the corners of each tile, an the text to display. +my $num = 0; foreach my $map (@mapset) { my $name = $map->{filename}; @@ -369,7 +385,7 @@ foreach my $map (@mapset) { my $geot = [ $ds->GetGeoTransform() ]; $map->{t_corners} = [ map [ Geo::GDAL::ApplyGeoTransform($geot, @$_) ], - ( [ 0, 0] + ( [ 0, 0 ] , [ 0, $ds->{RasterYSize}-1 ] , [ $ds->{RasterXSize}-1, 0 ] , [ $ds->{RasterXSize}-1, $ds->{RasterYSize}-1 ] @@ -395,7 +411,13 @@ foreach my $map (@mapset) { } { local $_ = basename $name; eval $config{rename}; $map->{text} = $_; } + if ($config{numeric}) { + my $fh = $config{numeric}; + printf $fh $config{numeric_format}.': '.$map->{text}."\n", ++$num; + $map->{text} = sprintf $config{numeric_format}, $num; + } } +close $config{numeric} if $config{numeric}; # Working directory |