Mapscript - Perl - Query - shapeObj
Sean Gillies
sgillies at FRII.COM
Tue Jan 18 07:02:13 PST 2005
On Jan 18, 2005, at 7:17 AM, Aaron Craig wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> The values property in the Perl implementation of a shapeObj is a
> scalar
> reference.
>
> I was hoping that it would be a hashref to my database columns for the
> record returned by a layerObj->queryByPoint() call, similar to what it
> looks like PHP does.
>
> My output looks like:
>
> <snipping code>
> my $res = $lyr->getResult(0);
> my $shp = mapscript::shapeObj->new($mapscript::MS_SHAPE_POLYGON);
> $lyr->getShape($shp, $res->{tileindex}, $res->{shapeindex});
> print "values: $shp->{values}\n";
>
> values: _p_p_char=SCALAR(0xa3e7d74)
>
> In the end I need to get an id value out of the database from my query.
> ~ Is there a standard way of doing this?
>
>
> Thanks again for the help.
>
> - --
> Aaron Craig
> mercutio at pobox.com
>
Aaron,
Here is the canonical query example (in Python) for version 4.4:
layer.query() # queryByRect or *Shape or *Attributes
results = layer.getResults()
if results:
# open layer in preparation of reading shapes
layer.open()
for i in range(results.numresults):
r = results.getResult(i)
feature = layer.getFeature(r.shapeindex, r.tileindex)
# Iterate over feature attributes
for j in range(layer.numitems):
att_name = layer.getItem(j)
att_val = feature.getValue(j)
print att_name, att_val
# Close when done
layer.close()
The PHP mapscript exposes the items and values as arrays, but this is
less feasible for the other mapscript modules due to differences in
their array implementations.
cheers,
Sean
--
Sean Gillies
sgillies at frii dot com
http://users.frii.com/sgillies
More information about the MapServer-users
mailing list