[mapserver-users] Problems with Perl mapscript and save()

Jean-Francois.Doyon at ccrs.nrcan.gc.ca Jean-Francois.Doyon at ccrs.nrcan.gc.ca
Wed Nov 13 16:55:29 EST 2002


Hello,

I'm trying to run a batch process on a bunch of mapfiles, so I wrote a
little perl/mapscript script to help me along (Find it below).

I'm having 2 problems, one seems to have something to do with re-entrancy
and the destruction/creation of the object, and the other with the save()
function.

Here is the output I get when I run my script:

[root at grumbler root]# ./mapfiledit.pl -d english/ -w newmapfiles/
english/10.map
newmapfiles/10.map
        (in cleanup) Not a HASH reference at
/usr/lib/perl5/site_perl/5.6.1/i386-linux/mapscript.pm line 2415.
english/105.map
newmapfiles/105.map
Can't call method "save" on unblessed reference at ./mapfiledit.pl line 35.

The errors seem to have something to do with the destruction of the object,
but I can't really figure out what the cause is.

Also, possibly related, the save() function does nothing!

Here is the code, it is simple:

#!/usr/bin/perl -w
 
use strict;
 
use mapscript;
 
use Getopt::Std;
our($opt_d,$opt_h,$opt_w);
getopts('hd:w:');
 
if ( $opt_h ) {
        print "MapFile Mass Updater\n\n\t-d\tDirectory where mapfiles are
located\n\n\t-w Directory to write files to.\n\n\t-h\tThis help.\n\n";
        exit;
}
 
if (! $opt_d ) {
        print "\nYou MUST provide the directory name to work on with the -d
option.  See -h for help.\n\n";
        exit;
}
 
if (! $opt_w ) {
        print "\nYou MUST provide the directory name to write to with the -w
option.  See -h for help.\n\n";
        exit;
}
 
sub workmapfile {
        my $mapfile = $_[0].$_[1];
        print $mapfile."\n";
        my $map = new mapObj($mapfile);
        $map->{scalebar}->{imagecolor}->{red} = 204;
        $map->{scalebar}->{imagecolor}->{green} = 204;
        $map->{scalebar}->{imagecolor}->{blue} = 204;
        my $outputfile = $opt_w.$_[1];
        print $outputfile."\n";
        $map->save($outputfile);
}
 
sub walkmapdir {
        my $mapfiledir = $_[0];
        opendir(MAPDIR,$mapfiledir);
        while ( my $direntry = readdir(MAPDIR) ) {
                if ( $direntry ne '.' && $direntry ne '..' ) {
                        if ( $direntry =~ /.*\.map$/ ) {
                                workmapfile($_[0],$direntry);
                        }
                }
        }
}
 
if ( -d $opt_d ) { if ( substr($opt_d,-1,1) ne "/" ) { $opt_d = $opt_d."/" }
walkmapdir($opt_d) }

Am I doing anything wrong ??? Anybody have any idea how to get around this ?

Thanks,

Jean-François Doyon
Internet Service Development and Systems Support
GeoAccess Division
Canada Center for Remote Sensing
Natural Resources Canada
http://atlas.gc.ca
Phone: (613) 992-4902
Fax: (613) 947-2410





More information about the mapserver-users mailing list