Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 anymore, 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?

share|improve this question

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)
// 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;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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