<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
</head>
<body>
How many bands are in the raster?
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> mapserver-users <mapserver-users-bounces@lists.osgeo.org> on behalf of Moen, Paul T. <pmoen@nd.gov><br>
<b>Sent:</b> Thursday, December 13, 2018 10:32:44 AM<br>
<b>To:</b> mapserver-users@lists.osgeo.org<br>
<b>Subject:</b> [mapserver-users] PHP MapScript queryByPoint fails successive query.</font>
<div> </div>
</div>
<style>
<!--
@font-face
        {font-family:"Cambria Math"}
@font-face
        {font-family:Calibri}
@font-face
        {font-family:Menlo}
p.x_MsoNormal, li.x_MsoNormal, div.x_MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Calibri",sans-serif}
a:link, span.x_MsoHyperlink
        {color:#0563C1;
        text-decoration:underline}
a:visited, span.x_MsoHyperlinkFollowed
        {color:#954F72;
        text-decoration:underline}
p.x_MsoListParagraph, li.x_MsoListParagraph, div.x_MsoListParagraph
        {margin-top:0in;
        margin-right:0in;
        margin-bottom:0in;
        margin-left:.5in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Calibri",sans-serif}
span.x_EmailStyle17
        {font-family:"Calibri",sans-serif;
        color:windowtext}
p.x_p1, li.x_p1, div.x_p1
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:8.5pt;
        font-family:Menlo;
        color:black}
span.x_s1
        {}
span.x_apple-converted-space
        {}
p.x_p2, li.x_p2, div.x_p2
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:8.5pt;
        font-family:Menlo;
        color:black}
.x_MsoChpDefault
        {font-family:"Calibri",sans-serif}
@page WordSection1
        {margin:1.0in 1.0in 1.0in 1.0in}
div.x_WordSection1
        {}
ol
        {margin-bottom:0in}
ul
        {margin-bottom:0in}
-->
</style>
<div lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="x_WordSection1">
<p class="x_MsoNormal"><span style="font-size:11.0pt"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">I am trying to query a raster at 2 points in a single php file using php mapscript.  </span></p>
<ol start="1" type="1" style="margin-top:0in">
<li class="x_MsoListParagraph" style="margin-left:.25in"><span style="font-size:11.0pt">I create a map object.</span></li><li class="x_MsoListParagraph" style="margin-left:.25in"><span style="font-size:11.0pt">I get a layer object from my raster</span></li><li class="x_MsoListParagraph" style="margin-left:.25in"><span style="font-size:11.0pt">I create 2 point objects.</span></li><li class="x_MsoListParagraph" style="margin-left:.25in"><span style="font-size:11.0pt">I query the raster layer object with queryByPoint using point 1 and it is successful, except that it gives me 4 results even though I pass in MS_SINGLE.</span></li><li class="x_MsoListParagraph" style="margin-left:.25in"><span style="font-size:11.0pt">I query the raster layer object a second time using queryByPoint with the second point object I created and the query fails.</span></li></ol>
<p class="x_MsoNormal"><span style="font-size:11.0pt"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">My questions:</span></p>
<p class="x_MsoNormal" style="text-indent:.5in"><span style="font-size:11.0pt">Shouldn’t this be possible? If so, what am I doing wrong?
</span></p>
<p class="x_MsoNormal" style="margin-left:.5in"><span style="font-size:11.0pt">Why are 4 points returned when I pass in MS_SINGLE?</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">I have tried using MapScript 7.2.1, 6.4.4 and 7.0.7 with the same results.</span></p>
<p class="x_p1"><span class="x_s1">MapScript</span></p>
<p class="x_p2"> </p>
<p class="x_p1"><span class="x_s1">MapServer Version => MapServer version 7.2.1 OUTPUT=PNG OUTPUT=JPEG OUTPUT=KML SUPPORTS=PROJ SUPPORTS=AGG SUPPORTS=FREETYPE SUPPORTS=CAIRO SUPPORTS=ICONV SUPPORTS=WMS_SERVER SUPPORTS=WMS_CLIENT SUPPORTS=WFS_SERVER SUPPORTS=WFS_CLIENT
 SUPPORTS=WCS_SERVER SUPPORTS=SOS_SERVER SUPPORTS=GEOS SUPPORTS=PBF INPUT=JPEG INPUT=POSTGIS INPUT=OGR INPUT=GDAL INPUT=SHAPEFILE</span></p>
<p class="x_p1"><span class="x_s1">PHP MapScript Version => ($Revision$ $Date$)</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt"> </span></p>
<p class="x_MsoNormal" style="background:white"><span style="font-size:8.5pt; font-family:Menlo; color:black">MapScript</span></p>
<p class="x_MsoNormal" style="background:white"><span style="font-size:8.5pt; font-family:Menlo; color:black"> </span></p>
<p class="x_MsoNormal" style="background:white"><span style="font-size:8.5pt; font-family:Menlo; color:black">MapServer Version => MapServer version 7.0.7 OUTPUT=PNG OUTPUT=JPEG OUTPUT=KML SUPPORTS=PROJ SUPPORTS=AGG SUPPORTS=FREETYPE SUPPORTS=CAIRO SUPPORTS=WMS_SERVER
 SUPPORTS=WMS_CLIENT SUPPORTS=WFS_SERVER SUPPORTS=WFS_CLIENT SUPPORTS=WCS_SERVER SUPPORTS=GEOS INPUT=JPEG INPUT=POSTGIS INPUT=OGR INPUT=GDAL INPUT=SHAPEFILE</span></p>
<p class="x_MsoNormal" style="background:white"><span style="font-size:8.5pt; font-family:Menlo; color:black">PHP MapScript Version => ($Revision$ $Date$)</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt"> </span></p>
<p class="x_MsoNormal" style="background:white"><span style="font-size:8.5pt; font-family:Menlo; color:black">MapScript</span></p>
<p class="x_MsoNormal" style="background:white"><span style="font-size:8.5pt; font-family:Menlo; color:black"> </span></p>
<p class="x_MsoNormal" style="background:white"><span style="font-size:8.5pt; font-family:Menlo; color:black">MapServer Version => MapServer version 6.4.4 OUTPUT=PNG OUTPUT=JPEG OUTPUT=KML SUPPORTS=PROJ SUPPORTS=AGG SUPPORTS=FREETYPE SUPPORTS=CAIRO SUPPORTS=WMS_SERVER
 SUPPORTS=WMS_CLIENT SUPPORTS=WFS_SERVER SUPPORTS=WFS_CLIENT SUPPORTS=WCS_SERVER SUPPORTS=GEOS INPUT=JPEG INPUT=POSTGIS INPUT=OGR INPUT=GDAL INPUT=SHAPEFILE</span></p>
<p class="x_MsoNormal" style="background:white"><span style="font-size:8.5pt; font-family:Menlo; color:black">PHP MapScript Version => ($Revision$ $Date$)</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">The code I am using is below.  I have set up a test script and sample data here
<a href="http://swc.nd.gov:8000/_Usd8Y3s4N9pgkR">http://swc.nd.gov:8000/_Usd8Y3s4N9pgkR</a>.</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">                The test can be run using php query.php 1 for the fail case. Running php query.php 2 is my work around using 2 map objects.</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">$map = new mapObj($path."/simple.map");</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">$qlay = $map->getLayerByName("qLayer");</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">$pq = ms_newPointObj();</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">$pq->setXY(567231,5086977); // 1298.609</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">$pq2 = ms_newPointObj();</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">$pq2->setXY(566445,5086590); // 1304.3274</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">$rastquery=$qlay->queryByPoint($pq,MS_SINGLE,1);</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">if($rastquery == MS_SUCCESS){</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">                error_log("Number of results from 1st query: ".$qlay->getNumResults()."\nShouldn't there be only 1 result since MS_SINGLE is passed?");</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">                if($qlay->getNumResults()>0){</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">                                $qlay->open();</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">                                for ($i=0; $i < $qlay->getNumResults(); $i++) {</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">                                                $rasresult = $qlay->getResult($i);</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">                                                if($rasresult === FALSE){</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">                                                                error_log('No result '.$i);</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">                                                } else {</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">                                                                $rasshptemp = $qlay->getShape($rasresult);</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">                                                                error_log("Result $i = ".$rasshptemp->values['value_0']);</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">                </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">                                                }</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">                                }</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">                }</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">} else {</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">                error_log('1st query failed');</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">}</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">$rastquery=$qlay->queryByPoint($pq2,MS_SINGLE,1);</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">if($rastquery == MS_SUCCESS){</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">                error_log("Number of results from 1st query: ".$qlay->getNumResults()."\nShouldn't there be only 1 result since MS_SINGLE is passed?");</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">                if($qlay->getNumResults()>0){</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">                                // error_log("In rastquery");</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">                                $qlay->open();</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">                                for ($i=0; $i < $qlay->getNumResults(); $i++) {</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">                                                $rasresult = $qlay->getResult($i);</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">                                                if($rasresult === FALSE){</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">                                                                error_log('No result'.$i);</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">                                                } else {</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">                                                                $rasshptemp = $qlay->getShape($rasresult);</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">                                                                error_log("Result $i = ".$rasshptemp->values['value_0']);</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">                                                }</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">                                }</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">                }</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">} else {</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">                error_log('2nd query failed!');</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">}</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">break;</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">Results</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt"> </span></p>
<p class="x_p1"><span class="x_s1">php query.php 1</span></p>
<p class="x_p1"> </p>
<p class="x_p1"><span class="x_s1">Number of results from 1st query: 4</span></p>
<p class="x_p1"><span class="x_s1">Shouldn't there be only 1 result since MS_SINGLE is passed?</span></p>
<p class="x_p1"><span class="x_s1">Result 0 = 1298.5105</span></p>
<p class="x_p1"><span class="x_s1">Result 1 = 1298.5105</span></p>
<p class="x_p1"><span class="x_s1">Result 2 = 1298.5105</span></p>
<p class="x_p1"><span class="x_s1">Result 3 = 1298.5105</span></p>
<p class="x_p1"><span class="x_s1">[Thu Dec 13 10:17:07 2018].185483 msQueryByPoint(): Search returned no results. No matching record(s) found.</span></p>
<p class="x_p1"><span class="x_s1">PHP Warning:</span><span class="x_apple-converted-space"> 
</span><span class="x_s1">layerObj::queryByPoint(): [MapServer Error]: msQueryByPoint(): No matching record(s) found.</span></p>
<p class="x_p1"><span class="x_apple-converted-space"> </span><span class="x_s1">in /Volumes/Data/WebServer/fris/php/test/query.php on line 36</span></p>
<p class="x_p1"><span class="x_s1">2nd query failed!</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">Any hints or help would be appreciated,
</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">Paul</span></p>
</div>
</div>
</body>
</html>