1

I upgraded my MapServer version from 5.6.x to 6.2.0 (yes, big version jump here!) and I am stuck with getting a shapeObj from a layer by simply using its Index (or FID for shapefiles or GID in case of PostGIS).

In the old version I used the following:

$layer->open();
$shapeOjbect = $layer->getFeature($fid);
$bounds = $shapeObject->bounds;`

which returned to me the rectangular bounds.

Everything has changed in the new version of MapServer/MapScript. GetFeature() is not enabled any more, and $layerObj->getShape($resultObj) can be used instead BUT getShape requires the resultObj(nth result) from a $layerObj->queryByXXX , but there is no XXX = Index (e.g. $layerObj->queryByIndex($fid) ).

There is a $mapObj->queryByIndex(layerIndex, tileIndex, $fid, [$addToquery]), but I have not seen any examples using that function.

I hope I explained clearly.

Does anybody have any experiences on using this function?

nmtoken
13.6k5 gold badges39 silver badges91 bronze badges
asked May 6, 2013 at 8:05

2 Answers 2

2

I found that there actually is a method for querying by Index in the layerObj
$layerObj->queryByIndex(???, $fid)
where ??? is probably the tileIndex of a layer object.

Maybe I missed it in the documentation, but I am pretty sure that it is not there. I only found a int queryByIndex(....) in the mapObj section, but none in the layerObj section of the Mapserver Mapscript documentation.

So here is a summary of the method;

// query my layerObj ($layer) by my index valu ($myFID)
$layer->queryByIndex(0,$myFID);
// gets the first result, unique obviously because I query a single index ($myFID)
$result = $layer->getResult(0); 
// use the resultObject ($result) to get the respective shapeObj ($shape)
$shape = $layer->getShape($result);
// get the bounds attribute
$rect = $shape->bounds;
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
answered May 6, 2013 at 8:58
1

I cannot comment on the answer which is a great answer, but wanted to add that I believe with 7.0 now you have to add a $map var in the query like:

$layer->queryByIndex($map, 0, $myFID);
answered May 2, 2019 at 16:46

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.