I'm using Mapserver 7.4.0-dev and MapScript PHP.

In previous versions of MapServer and MapScript (https://mapserver.org/mapscript/php/index-5.6.html#shapeobj), I could query a shapeObj after its values. And get a key => value array with all the data fields.


public function __construct(\shapeObj $shape)
    foreach ($shape->values as $key => $value) {
        //Do something;

In the new Mapserver and MapScript (https://mapserver.org/mapscript/mapscript.html#shapeobj), there is no $shape->values attribute.

I can get the value of element X but no the key name (Example "Gis_ID") by using this function:


But this does not help my much. My map sources are dynamic and i need to target the data by IDs, and not a random array index.

Can anyone help me figure this out? :)

1 Answer 1


Thanks to @interactivegis.com for answer on MS4W-mailing list

Hi Kenneth,

The example code we sent out earlier today actually helps with this as well. The IDs are now in the layer object, so after you get the $layer and get a shape using the layerObj Methods (like queryBy or nextShape or whatever from https://www.mapserver.org/mapscript/mapscript.html#layerobj-methods) you can use $layer->numitems there to see how many attribute fields the shapes have and loop over that using $layer->getItem($x) to get the names of those attribute fields.

This should let you create an array using $layer->getItem() (which I called $layer_headers in my sample code) which has the same numeric indexes as your $shape->getValue, but the $layer->getItem() values are the field names, so you can use a line like this to target an attribute directly once you've created the $layer_headers array:

$shape->getValue(array_search('Gis_ID', $layer_headers));

Depending on your needs you could loop through all of $layer->getItem() and all of $shape->getValue() and create an array that matches them up since the numerical indexes would always be a match, which is more of what the sample code from earlier at https://gist.github.com/andrewteg/81b8d45948d67003f5f1170e51d66e61 does.

Hope that helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.