[mapserver-users] small Perl mapscript example correction

Puneet Kishor pkishor at GeoAnalytics.com
Fri Mar 1 00:55:47 EST 2002


if some green-behind-the-ears Perl jockey like me is trying out the 
examples that come with ms3.5, please note the syntax of the Xbase 
package has changed. I have made the corrections to the shpinfo.pl 
script so it works correctly. Here is the modified version with the 
corrections commented. Hope it saves someone some time --


======

#!/usr/bin/perl

use Xbase;
# was: use XBase;
# changed all instances of XBase to Xbase

use mapscript;
use Getopt::Long;

%types = ( '1' => 'point',
            '3' => 'arc',
            '5' => 'polygon',
            '8' => 'multipoint'
          );

&GetOptions("file=s", \$file);
if(!$file) {
   print "Syntax: shpinfo.pl -file=[filename]\n";
   exit 0;
}

$shapefile = new shapefileObj($file, -1) or die "Unable to open 
shapefile $file.";

print "Shapefile $file:\n\n";
print "\ttype: ". $types{$shapefile->{type}} ."\n";
print "\tnumber of features: ". $shapefile->{numshapes} ."\n";
printf "\tbounds: (%f,%f) (%f,%f)\n", $shapefile->{bounds}->{minx}, 
$shapefile->{bounds}->{miny}, $shapefile->{bounds}->{maxx}, 
$shapefile->{bounds}->{maxy};


$table = new Xbase;
# was: $table = new Xbase $file.'.dbf' or die Xbase->errstr;

# added the following
$table->open_dbf($file.'.dbf') or die Xbase->errstr;

print "\nXbase table $file.dbf:\n\n";

print "\tnumber of records: ". ($table->lastrec+1) ."\n\n";
# was: $table->last_record

# the following lines are not needed. See note below.
#print "\tnumber of fields: ". ($table->last_field+1) ."\n\n";

#print "\tName             Type Length Decimals\n";
#print "\t---------------- ---- ------ --------\n";
#foreach ($table->field_names) {
#  printf "\t%-16s %4s %6d %8d\n", $_, $table->field_type($_), 
$table->field_length($_), $table->field_decimal($_)
#}

# all of the above replaced by
$table->dbf_stat;

# added the following
$table->close_dbf;




More information about the mapserver-users mailing list