<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 11 (filtered medium)">
<style>
<!--
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:Arial;
        color:windowtext;}
@page Section1
        {size:841.9pt 595.3pt;
        margin:89.85pt 72.0pt 89.85pt 72.0pt;}
div.Section1
        {page:Section1;}
-->
</style>
</head>
<body lang="EN-GB" link="blue" vlink="purple">
<div class="Section1">
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">I am running MapServer 5.4.2 and PHP 5.3.<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial"><o:p>&nbsp;</o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">As a PHP/Mapscript novice, I am using Kropla&#8217;s
<i><span style="font-style:italic">Beginning MapServer </span></i>(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.<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial"><o:p>&nbsp;</o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">This is Kropla&#8217;s function which finds point locations within the radius. The arguments to NearbyStores() are point object, map object and radius value(miles)
 respectively:<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial"><o:p>&nbsp;</o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">function NearbyStores($point,$map,$radius) {<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">&nbsp;&nbsp;&nbsp;&nbsp; // get query layer<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">&nbsp;&nbsp;&nbsp;&nbsp; $qlayer = $map-&gt;getLayerByName('poi');<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">&nbsp;&nbsp;&nbsp;&nbsp; $qlayer-&gt;set(&quot;tolerance&quot;,$radius);<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial"><o:p>&nbsp;</o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">&nbsp;&nbsp;&nbsp;&nbsp; // query the query layer - $radius is set in browser<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">&nbsp;&nbsp;&nbsp;&nbsp; // queryByPoint ignores TOLERANCE units using native map units<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">&nbsp;&nbsp;&nbsp;&nbsp; // instead - in this case decimal degrees. The number of miles<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">&nbsp;&nbsp;&nbsp;&nbsp; // per degree is (approximately of course) 69.04 therefore<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">&nbsp;&nbsp;&nbsp;&nbsp; // the correction from degrees to miles. This would have to<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">&nbsp;&nbsp;&nbsp;&nbsp; // change if TOLERANCEUNITS, the map or scale units change.<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial"><o:p>&nbsp;</o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">&nbsp;&nbsp;&nbsp;&nbsp; @$qlayer-&gt;queryByPoint($point, MS_MULTIPLE, $radius/69.04);<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">&nbsp;&nbsp;&nbsp;&nbsp; $numResults = $qlayer-&gt;getNumResults();<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">&nbsp;&nbsp;&nbsp;&nbsp;
<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">&nbsp;&nbsp;&nbsp;&nbsp; // we've got results, store id equals shape index<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial"><o:p>&nbsp;</o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">&nbsp;&nbsp;&nbsp;&nbsp; if ($numResults != 0) {<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for ($i = 0; $i &lt; $numResults; $i&#43;&#43;) {<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $query_result = $qlayer-&gt;getResult($i);<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;$StoreList[$i] = $query_result-&gt;shapeindex;<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">&nbsp;&nbsp;&nbsp;&nbsp; } else {<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $StoreList = &quot;&quot;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // no results<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">&nbsp;&nbsp;&nbsp;&nbsp; }<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">&nbsp;&nbsp;&nbsp;&nbsp; return $StoreList;<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">}<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial"><o:p>&nbsp;</o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">The variable $numResults appears to correctly identify the number of locations within your input radius. But $query_result-&gt;shapeindex behaves strangely. The
 array $Storelist[], when populated with all five restaurant store-ids in the database using function NearbyStores(),
<i><span style="font-style:italic">should</span></i> 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.<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial"><o:p>&nbsp;</o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">Is anyone familiar with Kropla&#8217;s book, or can anyone explain this behaviour by the various PHP/Mapserver functions shown above or suggest a reasonable alternative?<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial"><o:p>&nbsp;</o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">Many Thanks,<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">Rob Pearce<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial"><o:p>&nbsp;</o:p></span></font></p>
</div>
<br>
<hr>
<font face="Arial" color="Gray" size="1">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.<br>
No binding contract will result from this e-mail until and unless an officer, on behalf of the sender, signs a written document.<br>
Sender accepts no responsibility for the completeness or accuracy of this message as it has been transmitted over public networks.<br>
Unless otherwise specifically stated any views or opinions are solely those of the author and do not represent those of the sender Company.<br>
</font>
<BR>
_____________________________________________________________________________________________________________________<BR>
This email has been scanned by the MessageLabs Email Security System, on behalf of the Gardline Group of Companies.<BR>
For more information please visit http://www.messagelabs.com/email <BR>
_____________________________________________________________________________________________________________________<BR>
</body>
</html>