Subject: | GDAL.pm processes parameters with more than one argument using a hash reference in an unexpected way |
Date: | Mon, 6 Mar 2017 20:41:34 +0000 |
To: | "bug-Geo-GDAL [...] rt.cpan.org" <bug-Geo-GDAL [...] rt.cpan.org> |
From: | "Dr. Peter A. J. Liggatt" <pliggatt [...] microdecisions.com> |
We are running perl 5.16.3 built for x86_64-linux-thread-multi on linux 3.10.0-327.10.1.el7.x86_64
In GDAL.pm version 2.0.12 built by SWIG during a GDAL source build, there is the following subroutine at line 1402:
sub make_processing_options {
my ($o) = @_;
if (ref $o eq 'HASH') {
for my $key (keys %$o) {
unless ($key =~ /^-/) {
$o->{'-'.$key} = $o->{$key};
delete $o->{$key};
}
}
$o = [%$o];
}
return $o;
}
The highlighted line will correctly convert arguments such as
-of => 'gtiff', '-r' => 'Lanczos'
as expected. However, for example, gdalwarp accepts parameters such as -te that have more than one argument. The documentation does describe that a list reference such as ['-tr', 10, 10] can be used, but that path through the code will not add a leading hyphen to, say, ['tr', 10, 10], and the hash reference / named parameter form seems to be a cleaner approach when passing many parameters. More so, this seems to be a trap for the unwary who try, say, '-ts' => '2048 2048' to have it fail mysteriously. After all, the documentation does not explicitly exclude that syntax and the error from gdalwarp is that the parameter is unknown rather than it has the wrong number of arguments.
I would suggest that the highlighted line be recoded to be DWIM - the written construct is unusual and opaque - so that the syntax 'ts' => '2048 2048' succeeds, or at least the documentation be clarified that the hash reference form does not work for multiple arguments.
The following line would appear to do that, but this is also opaque and it might be better to review the for loop instead.
$o = [ map { $_, split(/\s+/, $o->{$_}) } keys %$o ];
Dr. Peter A. J. Liggatt
President
MicroDecisions, Inc.
Tel: 407-843-1550
E-mail: pliggatt@microdecisions.com<mailto:pliggatt@microdecisions.com>
Website: www.microbase.com<http://www.microbase.com/>