<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style>
<!--
@font-face
        {font-family:Calibri}
@font-face
        {font-family:Tahoma}
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif"}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif"}
p.msochpdefault, li.msochpdefault, div.msochpdefault
        {margin-right:0in;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Calibri","sans-serif"}
span.emailstyle17
        {font-family:"Calibri","sans-serif";
        color:windowtext}
span.EmailStyle19
        {font-family:"Calibri","sans-serif";
        color:#1F497D}
span.BalloonTextChar
        {font-family:"Tahoma","sans-serif"}
.MsoChpDefault
        {font-size:10.0pt;
        font-family:"Calibri","sans-serif"}
@page WordSection1
        {margin:1.0in 1.0in 1.0in 1.0in}
-->
</style><style type="text/css" id="owaParaStyle"></style>
</head>
<body lang="EN-US" link="blue" vlink="purple" fpstyle="1" ocsi="0">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">It shouldn't matter the shape type. Could it be projection related? Perhaps tolerance related?
<div><br>
</div>
<div>Steve<br>
<div style="font-family: Times New Roman; color: #000000; font-size: 16px"><br>
<hr tabindex="-1">
<div id="divRpF528646" style="direction: ltr;"><font face="Tahoma" size="2" color="#000000"><b>From:</b> Bistrais, Bob [Bob.Bistrais@maine.gov]<br>
<b>Sent:</b> Wednesday, February 20, 2013 3:34 PM<br>
<b>To:</b> Lime, Steve D (MNIT); mapserver-users@lists.osgeo.org<br>
<b>Subject:</b> RE: queryByShape returns too many results<br>
</font><br>
</div>
<div></div>
<div>
<div class="WordSection1">
<p class="MsoNormal"><span style="color:#1F497D">Thanks Steve.  </span></p>
<p class="MsoNormal"><span style="color:#1F497D"> </span></p>
<p class="MsoNormal"><span style="color:#1F497D">Interestingly, the process you showed me works great with my point data.  But with line or poly data, I am getting some results outside of the polygon.  But, using the nextShape() method works properly with these. 
</span></p>
<p class="MsoNormal"><span style="color:#1F497D"> </span></p>
<p class="MsoNormal"><span style="color:#1F497D">I can but some if/then code in to examine the results based on feature type.  But it would be interesting to know why one way works best for points, the other for lines/polys.  </span></p>
<p class="MsoNormal"><span style="color:#1F497D"> </span></p>
<div>
<div style="border:none; border-top:solid #B5C4DF 1.0pt; padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt; font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt; font-family:"Tahoma","sans-serif""> Lime, Steve D (MNIT) [mailto:Steve.Lime@state.mn.us]
<br>
<b>Sent:</b> Wednesday, February 20, 2013 4:06 PM<br>
<b>To:</b> Bistrais, Bob; mapserver-users@lists.osgeo.org<br>
<b>Subject:</b> RE: queryByShape returns too many results</span></p>
</div>
</div>
<p class="MsoNormal"> </p>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt; color:black">You don't use the nextShape() method to retrieve shapes as a result of a query. Here's the pseudo code:</span><span style="font-size:10.0pt; font-family:"Tahoma","sans-serif"; color:black">
</span></p>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:"Tahoma","sans-serif"; color:black"> </span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt; color:black">$layer->queryByShape($q_shape);</span><span style="font-size:10.0pt; font-family:"Tahoma","sans-serif"; color:black"></span></p>
</div>
<div>
<table class="MsoNormalTable" border="0" cellpadding="0">
<tbody>
<tr>
<td style="padding:.75pt .75pt .75pt .75pt">
<p class="MsoNormal"><span style="font-size:12.0pt">for($i=0; $i < $layer->getNumResults(); $i++) {<br>
  $shape = $layer->getShape($layer->getResult($i));<br>
  .. do something with the shape ..<br>
}</span><span style="font-size:12.0pt; font-family:"Times New Roman","serif""></span></p>
</td>
</tr>
<tr>
<td style="padding:.75pt .75pt .75pt .75pt">
<p class="MsoNormal" style="margin-bottom:12.0pt"><span style="font-size:12.0pt"><br>
As part of query operations the bounding box of $q_shape was used to select candidate shapes (that's why nextShape() is returning what is does).</span><span style="font-size:12.0pt; font-family:"Times New Roman","serif""><br>
<br>
Steve</span></p>
</td>
<td style="padding:.75pt .75pt .75pt .75pt"></td>
</tr>
</tbody>
</table>
</div>
<div>
<div>
<div class="MsoNormal" align="center" style="text-align:center"><span style="font-size:12.0pt; font-family:"Times New Roman","serif"; color:black">
<hr size="2" width="100%" align="center">
</span></div>
<div id="divRpF783239">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="font-size:10.0pt; font-family:"Tahoma","sans-serif"; color:black">From:</span></b><span style="font-size:10.0pt; font-family:"Tahoma","sans-serif"; color:black">
<a href="mailto:mapserver-users-bounces@lists.osgeo.org" target="_blank">mapserver-users-bounces@lists.osgeo.org</a> [mapserver-users-bounces@lists.osgeo.org] on behalf of Bistrais, Bob [Bob.Bistrais@maine.gov]<br>
<b>Sent:</b> Wednesday, February 20, 2013 2:38 PM<br>
<b>To:</b> <a href="mailto:mapserver-users@lists.osgeo.org" target="_blank">mapserver-users@lists.osgeo.org</a><br>
<b>Subject:</b> [mapserver-users] queryByShape returns too many results</span><span style="font-size:12.0pt; font-family:"Times New Roman","serif"; color:black"></span></p>
</div>
<div>
<div>
<p class="MsoNormal"><span style="color:black">I am working on a spatial query module (actually, modifying an existing GeoMoose module) which uses queryByShape to take a previously selected feature from one layer, and use it to select features from another
 layer.  Both layers are shapefiles, the query layer is of course polygon, the selection layer is points in this case. 
</span></p>
<p class="MsoNormal"><span style="color:black"> </span></p>
<p class="MsoNormal"><span style="color:black">When I do the query I am finding too many results are returned- there are many features outside the query polygon which are selected, well beyond the polygon boundary.   The selected features might possibly be
 within the BBOX of the polygon, but I only want what’s within the polygon.</span></p>
<p class="MsoNormal"><span style="color:black"> </span></p>
<p class="MsoNormal"><span style="color:black"> </span></p>
<p class="MsoNormal"><span style="color:black">                $layer->queryByShape($q_shape);</span></p>
<p class="MsoNormal"><span style="color:black">                while($shape = $layer->nextShape()) {</span></p>
<p class="MsoNormal"><span style="color:black">                                # if we have a projection, convert the shape into latlong</span></p>
<p class="MsoNormal"><span style="color:black">                                if($q_shape->intersects($shape) == MS_TRUE or $shape->containsShape($q_shape) == MS_TRUE) {</span></p>
<p class="MsoNormal"><span style="color:black">                                                if($projection != NULL) {</span></p>
<p class="MsoNormal"><span style="color:black">                                                                $shape->project($projection, $LATLONG_PROJ);</span></p>
<p class="MsoNormal"><span style="color:black">                                                }</span></p>
<p class="MsoNormal"><span style="color:black">                                                $foundShapes[] = $shape;</span></p>
<p class="MsoNormal"><span style="color:black">                                }</span></p>
<p class="MsoNormal"><span style="color:black">                }</span></p>
<p class="MsoNormal"><span style="color:black"> </span></p>
<p class="MsoNormal"><span style="color:black"> </span></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>