[Mapserver-users] Get attribute values from Shapefile

Norbert Thieme norbert.thieme at ilmenau.baw.de
Wed May 5 03:17:26 EDT 2004

Ganesh Pulicherla schrieb:
> 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:

	        $items = $layer->getitems();

To get the values from one query result use this:

	        $data_shp = $layer->getshape($tile_index, $shape_index);
	        $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.


More information about the mapserver-users mailing list