How to get Shapefile Attributes in PHP?

John Kim jkim at SCIENCES.SDSU.EDU
Wed May 3 13:23:19 PDT 2006


Norbert wrote:
> if I remember correctly you have to:
> 1. get a layer
> 2. open the layer
> 3. get a feature from the layer with shape- and tileindex
> 4. get a value from the feature (loop through with the numvalues)
> 5. close the layer

Thanks Norbert. By fishing around the documentation and email archives (for way too long!) and by trial-and-error I figure out this code:

$layer->open();
for ($i=0; $i<13; $i++) {
        $shp = $layer->getShape(-1, $i);
        echo $shp->getvalue($layer, "myfieldname");
}
$layer->close();

I don't know how to obtain the number of ShapeObj's in the layer, so I just hardwired 13 in there because I knew there were 13 points in the layer I was accessing. But there must be some attribute to the LayerObj or a function call that returns that number?

John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20060503/5e272079/attachment.htm>


More information about the MapServer-users mailing list