<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style>
<!--
@font-face
        {font-family:Calibri}
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}
span.EmailStyle17
        {font-family:"Calibri","sans-serif";
        color:windowtext}
.MsoChpDefault
        {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;"><font face="Calibri" size="3">You don't use the nextShape() method to retrieve shapes as a result of a query. Here's the pseudo code:</font>
<div><font face="Calibri" size="3"><br>
</font></div>
<div><font face="Calibri" size="3">$layer->queryByShape($q_shape);</font></div>
<div>
<table>
<tbody>
<tr>
<td class="webkit-line-content"><font face="Calibri">for($i=0; $i < $layer->getNumResults(); $i++) {<br>
  $shape = $layer->getShape($layer->getResult($i));<br>
  .. do something with the shape ..<br>
}</font></td>
</tr>
<tr>
<td class="webkit-line-number"><font face="Calibri"><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).</font><br>
<br>
Steve<br>
<br>
</td>
<td class="webkit-line-content"><br>
</td>
</tr>
</tbody>
</table>
</div>
<div>
<div style="font-family: Times New Roman; color: #000000; font-size: 16px">
<hr tabindex="-1">
<div id="divRpF783239" style="direction: ltr;"><font face="Tahoma" size="2" color="#000000"><b>From:</b> mapserver-users-bounces@lists.osgeo.org [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> mapserver-users@lists.osgeo.org<br>
<b>Subject:</b> [mapserver-users] queryByShape returns too many results<br>
</font><br>
</div>
<div></div>
<div>
<div class="WordSection1">
<p class="MsoNormal">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. 
</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">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.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">                $layer->queryByShape($q_shape);</p>
<p class="MsoNormal">                while($shape = $layer->nextShape()) {</p>
<p class="MsoNormal">                                # if we have a projection, convert the shape into latlong</p>
<p class="MsoNormal">                                if($q_shape->intersects($shape) == MS_TRUE or $shape->containsShape($q_shape) == MS_TRUE) {</p>
<p class="MsoNormal">                                                if($projection != NULL) {</p>
<p class="MsoNormal">                                                                $shape->project($projection, $LATLONG_PROJ);</p>
<p class="MsoNormal">                                                }</p>
<p class="MsoNormal">                                                $foundShapes[] = $shape;</p>
<p class="MsoNormal">                                }</p>
<p class="MsoNormal">                }</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"> </p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>