[Mapserver-users] Get attribute values from Shapefile

Ganesh Pulicherla ganesh at cs.und.edu
Thu May 6 14:48:15 EDT 2004

Thanks a lot for replying so fast to my question.
I have tried the method you have given me, it gives me all the county names 
but at the end it gives me an error. I guess, i donot have to make a query to 
the layer, isn't it ? As far as i understand i have to open the shape file, 
read the column names, and get all the shapes in an array. I was doing this 
with the following code but it gives me an error 
"Fatal error: [MapServer Error]: msLayerGetShape(): Invalid feature id"
I understand that the problem is i am trying to get the shapes even after all 
the records are over, but how can i know the number of shapes(records) in the 
dbf file. 
for ($i=0;$layer->getShape(-1,$i);$i++)         //End loop if there is no shape
{       $data_shp = $layer->getshape(-1 , $i);
        $data = $data_shp->values;
        echo $data[$items[0]];         //items[0] has the column name

Can you tell me how to get the number of shapes/records in the dbf file so 
that, i can exit the loop.

> > Hello everyone
> > 
> > We are using PHP/Mapscript on Linux. I have a quick question: How can i get
> the 
> > attribute values of a Shape file using PHP/Mapscript ? For eg., In the
> Counties 
> > shapefile, i want to retrieve all the county names under the C_NAME column
> in 
> > the shapefile. 
> > Any help is greatly appreciated.
> > 
> > Thanks in advance
> > Ganesh 
> > 
> > 
> > 
> > _______________________________________________
> > Mapserver-users mailing list
> > Mapserver-users at lists.gis.umn.edu
> > http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
> > 
> > 
> This is simple. There is a way in php to use php's dbase functions. I 
> could tell you that but there is a better way by using the mapscript 
> functions itself. The advantage of this is that it gives you the values 
> of all(?) queryable data. To get the field names use this:
> 	        $layer->open();
> 	        $items = $layer->getitems();
> 	        $layer->close();
> To get the values from one query result use this:
> 	        $layer->open();
> 	        $data_shp = $layer->getshape($tile_index, $shape_index);
> 	        $layer->close();
> 	        $data = $data_shp->values;
> So you have two arrays - one with the field names and one with the 
> values. Loop through the first to get the index of the field you search 
> and take this index to the second array to get the value you want.
> Regards,
> Norbert

More information about the mapserver-users mailing list