[mapserver-users] mapscript getShape again...

Daniel Morissette morissette at dmsolutions.ca
Thu Dec 20 15:09:22 EST 2001


Stephen Lime wrote:
> 
> 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.
> 


What Steve writes is true with the Perl and other SWIG-based versions of
MapScript, but the PHP MapScript does return the attributes of the
shapeObj in an associative array (hash table in Perl terms I think) no
matter what the data source is, so accessing $shp->values["UF"] is valid
with PHP MapScript.

> 
>          $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??
> 

Yes, you have to call open() first before any call to getShape()... and
you should call close() once you're done.

But I would expect PHP to produce an error message in your case... not
to hang... bizarre.


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

MAXFEATURES seems to be a setting in the layerObj in the mapfile... not
sure what it does though.

The open()/getShape()/close() calls were mostly intended for use with
the shape ids returned by a query, so there is currently no way to find
out the number of shapes in a layer or to read all shapes from a layer
in sequential order... you should use shapeFileObj as Steve suggested
for that.

Maybe a $layer->getNextShape() call could be useful for cases where you
need to read all shapes from a layer's data source.  You may want to
file an enhancement request in the MapServer bugzilla about this.

-- 
------------------------------------------------------------
 Daniel Morissette               morissette at dmsolutions.ca
 DM Solutions Group              http://www.dmsolutions.ca/
------------------------------------------------------------
  Don't put for tomorrow what you can do today, because if 
      you enjoy it today you can do it again tomorrow.



More information about the mapserver-users mailing list