[MS4W-Users] Get data values from shapeObj MapScript
igis at interactivegis.com
igis at interactivegis.com
Fri Mar 29 13:09:08 EDT 2019
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 http://bit.ly/2OxnDih does.
Hope that helps!
------ Original Message ------
Hi there,
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.
Example:
public function __construct(\shapeObj $shape)
{
foreach ($shape->values as $key => $value) {
//Do something;
}
}
In the new Mapserver and MapScript, there is no $shape->values attribute.
I can get the value of element X but not the key name (Example "Gis_ID") by
using this function:
$shape->getValue(3);
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? :)
Hilsen
Kenneth Hauklien
kenneth at micado.no
https://www.micado.no
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ms4w.com/pipermail/ms4w-users/attachments/20190329/1e992f53/attachment.html>
More information about the MS4W-Users
mailing list