From 36fd682fbfb4389c3dc1138ee59526f914c919c7 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Sat, 17 Aug 2013 21:06:17 +0200 Subject: Ability to use number-only watermarks. --- mkindex.pl | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'mkindex.pl') diff --git a/mkindex.pl b/mkindex.pl index 467a296..295a60a 100755 --- a/mkindex.pl +++ b/mkindex.pl @@ -27,9 +27,10 @@ mkindex.pl - Create an index file from a mapset =head1 SYNOPSIS -B [B<-q>] [B<-d>] [B<--rename> I] [B<-s> I] -[B<-r> I] [B<-b> I] [B<-f> I] [B<--s_srs> I] -[B<--t_srs> I] [-o I] [B<--crop>] I [... I] I +B [B<-q>] [B<-d>] [B<--rename> I] [B<-n> I] +[B<-s> I] [B<-r> I] [B<-b> I] [B<-f> I] +[B<--s_srs> I] [B<--t_srs> I] [-o I] [B<--crop>] I +[... I] I B 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 section for other examples. +=item B<-n> I, B<--numeric>=I + +Instead of annoting the index with the map names, use an increasing +counter starting from 1, and write the mapping I in I, +where I is a map name massaged with I (see B<--rename>). +If I is a single hyphen-minus (I<->), the mapping is written to +the standard output. + =item B<-s> IxI, B<--size=>IxI The size of the output index (default: 1024x0). If I or I @@ -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 -- cgit v1.2.3