MapScript Shapefile Object

Chris Fuhrman cfuhrman at tfcci.com
Tue May 9 10:59:54 EDT 2000


Howdy,

I'm presently using Perl/Mapscript to connect to a remote database,
retrieve coordinate data, generate a shapefile, and then, from the
shapefile, generate an image.

What I'm having problems with is that I'm generating the shapefiles okay,
but when I look in the shapefile object, the numshapes attribute is set to
zero which means I can't iterate through it to draw all it's shapes.

According to the documentation, numshapes is a read-only attribute so I
assumed it would be updated automatically.

Here's some sample code (paraphrased :)

    foreach $layername (@layers) {

      	print "Generating $layername\n";
	$sth->execute(uc $layername);
	($layer_id, $type) = $sth->fetchrow();

	print "  Generating shapefile\n";

        # This returns a ShapefileObj
	$shapefile = GenShapefile($dbh,
				  $dbh_dbf,
				  $type,
				  $layer_id,
				  $layername,
				  $extent);
	
	print "Getting layer";
	$layer = $map->getLayerByName($layername);
	
	for ($i=0; $i<$shapefile->{numshapes}; $i++) {
	    
	    print ".";
	    $class = new classObj($layer);
	    $shapefile->get($i, $shape);
	    $shape->draw($map, $layer, $img, $class, "An object");

	} # for ($i=0; $i<$shapefile->{numshapes}; $i++) 
	print "\n";

	undef $shapefile;

    } # foreach $layername (@layers) {
    
    print "Saving image\n";
  mapscript::msSaveImage($img, "temp.png", 1, 1);

My question is that is $shapefile->{numshapes} supposed to be updated
automatically or do I have to keep track of it myself?  

I am using version 3.3.010 of MapScript with GD 1.7.3 compiled in.

Cheers!

-- 
Chris Fuhrman           | Twenty First Century Communications
cfuhrman at tfcci.com      | Software Engineer
(W) 614-442-1215 x271   |
(F) 614-442-5662        | PGP/GPG Public Key Available on Request




More information about the mapserver-users mailing list