[mapserver-users] Can't Get Kropla Fifth Map to work Properly

Robin Pearce robin.pearce at gardline.com
Tue Jan 18 04:43:18 EST 2011

I am running MapServer 5.4.2 and PHP 5.3.

As a PHP/Mapscript novice, I am using Kropla's Beginning MapServer (2005) to learn what I need to create my own mapping application. Chapter 9 describes a simple dataset of five restaurant locations added to a point layer, then queried using an input radius from a previously-clicked point. This is supposed to create a table of all locations(restaurants) within the radius.

This is Kropla's function which finds point locations within the radius. The arguments to NearbyStores() are point object, map object and radius value(miles) respectively:

function NearbyStores($point,$map,$radius) {
     // get query layer
     $qlayer = $map->getLayerByName('poi');

     // query the query layer - $radius is set in browser
     // queryByPoint ignores TOLERANCE units using native map units
     // instead - in this case decimal degrees. The number of miles
     // per degree is (approximately of course) 69.04 therefore
     // the correction from degrees to miles. This would have to
     // change if TOLERANCEUNITS, the map or scale units change.

     @$qlayer->queryByPoint($point, MS_MULTIPLE, $radius/69.04);
     $numResults = $qlayer->getNumResults();

     // we've got results, store id equals shape index

     if ($numResults != 0) {
          for ($i = 0; $i < $numResults; $i++) {
              $query_result = $qlayer->getResult($i);
              $StoreList[$i] = $query_result->shapeindex;
     } else {
          $StoreList = "";      // no results
     return $StoreList;

The variable $numResults appears to correctly identify the number of locations within your input radius. But $query_result->shapeindex behaves strangely. The array $Storelist[], when populated with all five restaurant store-ids in the database using function NearbyStores(), should contain 1,2,3,4,5 (there is no store id 0). However if only 1 location is found, $Storelist[] contains 0, if 2 locations, it contains 0,1 and if all five are found it contains 0,1,1,1,1. In other words, the first array element of $Storelist becomes zero and any subsequent elements are always 1. Consequently when you proceed to populate the display table for all five, you get details of the first location followed by four duplicates of the second.

Is anyone familiar with Kropla's book, or can anyone explain this behaviour by the various PHP/Mapserver functions shown above or suggest a reasonable alternative?

Many Thanks,
Rob Pearce

CONFIDENTIALITY - This e-mail and any attached files contain information that is confidential and/or may be subject of legal privilege, intended only for use by the addressee(s). If you are not the intended recipient or the person responsible for delivering the message to the intended recipient, please be advised that you have received this message in error and that any dissemination, copying or use of this message or attachment is strictly forbidden, as is the disclosure of the information therein. If you have received this message in error please notify the sender immediately and preserve this confidentiality by deleting the message.
No binding contract will result from this e-mail until and unless an officer, on behalf of the sender, signs a written document.
Sender accepts no responsibility for the completeness or accuracy of this message as it has been transmitted over public networks.
Unless otherwise specifically stated any views or opinions are solely those of the author and do not represent those of the sender Company.

This email has been scanned by the MessageLabs Email Security System, on behalf of the Gardline Group of Companies.
For more information please visit http://www.messagelabs.com/email 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapserver-users/attachments/20110118/afb6c1b3/attachment.html

More information about the mapserver-users mailing list