[mapserver-users] mapscript getShape again...

Stephen Lime steve.lime at dnr.state.mn.us
Thu Dec 20 14:20:59 EST 2001


In MapScript (at the moment anyway) attribute values are not directly accessible in the scripting language. The problem is in mapping a C array of strings to a scripting language equivalent (and doing this for 5 or 6 languages). I do hope to support this eventually.

There is a workaround for shapefiles. *yipee*

MapScript contains methods specific to shapefiles that allow you to read/write them. Plus, you can use a perl module like XBase.pm to access the attributes. Note that these methods work on a single shapefile at a time. You'd do something like:

$shapefile = new shapefileObj("test.shp", -1) or die 'Unable to open shapefile.';
$table = new XBase('test.dbf') or die XBase->errstr;

$shape = new shapeObj(-1); # or set an approriate type

for($i=0; $i<$shapefile->{numshapes}; $i++) {
   $shapefile->get($i, $shape); # fetch the vertices
   ($deleted, @values) = $table->get_record($i);

   # now do what you will...
}  

Again, the hope is that the same type of processing can be applied to all data sources, but at the moment the methods to support that haven't been written.

Steve

Stephen Lime
Data & Applications Manager

Minnesota DNR
500 Lafayette Road
St. Paul, MN 55155
651-297-2937

>>> Nicolau Werneck <nwerneck at yahoo.com.br> 12/20/01 10:57AM >>>
OK, last question was ridiculous, I admit it...

now, how do I open a layer to use getShape in it? I'm
doing this:

         $lyr=$map->getLayerByName("brest");
         $shp=$lyr->getShape(-1, 0);
         echo $shp->values["UF"]."<BR>";
         exit;

but it just hangs on... the first line is OK, I cant
take the layer's name from $lyr, but the getShape
isn't working.  Does it has something to do with that
open()  function??

also, how do I get the number of features in the
layer? should maxfeatures it? it's set to -1! :(

I've user the layer with mapserver and it's showing
the states allright...

thx

++nicolau



_______________________________________________________________________________________________
Yahoo! GeoCities
Tenha seu lugar na Web. Construa hoje mesmo sua home page no Yahoo! GeoCities. É fácil e grátis!
http://br.geocities.yahoo.com/




More information about the mapserver-users mailing list