[Mapserver-users] QueryByAttribute

Ryan, Adam ARyan at co.linn.or.us
Wed Apr 28 11:39:59 EDT 2004


This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C42D37.10966740
Content-Type: text/plain

 
Just a hunch, I needed parentheses.  Instead of 
 
$oQueryStatus = $oPincodeLayer->queryByAttributes("OUT_CODE",
"\"".$szPincode."\"",MS_SINGLE);

 
try
 
$oQueryStatus = $oPincodeLayer->queryByAttributes("OUT_CODE",
"(\"".$szPincode."\")",MS_SINGLE);

 
Hope it helps,
 
Adam
 

-----Original Message-----
From: Satyajit [mailto:satyajit.gantayat at aurovision.com] 
Sent: Wednesday, April 28, 2004 12:39 AM
To: mapserver-users at lists.gis.umn.edu
Subject: [Mapserver-users] QueryByAttribute


 Hi Folks,

       I have been banging my head since a couple of days with this code. I
am trying to build an application where the user can search for a specific
postcode and then the map will zoom into that particular extent. 
 When the user enters a postcode ( I call it PINCODE) in the inputbox we
search the pincode in the pincode shape file and set the map's extent to
that of the shape found.
But the following code is not working. The queryByAttributes function is
reporting MS_FAILURE. This code is some what similar to that in one of the
listings. It would beb great if somebody guide me through step by step
procedure of developing this kind of QueryByAttribute feature using
Mapserver.
 
 
if ($http_form_vars["Pincode"])
{
 // the pincode to query for
 $szPincode = $http_form_vars["Pincode"];
 
 $oPincodeLayer = $oMapSession->oMap->getLayerByName("Pincode");
 
// OUT_CODE is the field name which contains the value which would be
queried. 
 
$oQueryStatus = $oPincodeLayer->queryByAttributes("OUT_CODE",
"\"".$szPincode."\"",MS_SINGLE);
 
 if ( $oQueryStatus = MS_FAILURE )
 {
  echo  "<td ><b> Query Failed ... \"".$szPincode."\" </b></td>";
  echo "<td> Query Status = ".$oQueryStatus."</td>";
 }
 else
 {
  if ($oPincodeLayer->getNumResults() > 0)
  {
   $oResult = $oPincodeLayer->getResult(0);
   $oOpen = $oPincodeLayer->open();
   
   $oShape = $oPincodeLayer->getShape($oResult->tileindex,
$oResult->shapeid);
   
   $oExtents = $oShape->bounds;
   
   $oShape->free();
 
   //at this point we might add a buffer to the extents
   $nMinX = $oExtents->minx;
   $nMaxX = $oExtents->maxx;
   $nMinY = $oExtents->miny;
   $nMaxY = $oExtents->maxy;
   
   $oExtents->setExtent( $nMinX, $nMinY, $nMaxX, $nMaxY );
  }
  // now use $oMapNavigator to navigate to the parcel
  // location.  There are two useful options now.  We
  // can zoom to a rectangle which we have calculated or
  // to a point and scale.  Let's assume we have calculated
  // a rectangle and put a buffer around it if necessary.
  //$oMapNavigator->zoomRectangle($nMinX,  $nMinY,
        //$nMaxX, $nMaxY);
   $oMapSession->oMap->setExtent( $oExtents->minx, $oExtents->miny,
$oExtents->maxx, $oExtents->maxy );
 }
}
 

 I am using
    MapServer/MapScript 4.0
    PHP 4.3
    MapLab 2.1
   
 
Thanks and Regards
Satyajit G.
    
 



	Imaging the way ahead ...	
	

Satyajit Gantayat
Sr. Specialist GIS 	
Aurovision Pvt. Ltd.
101, Swati
North Avenue
Santacuz (w)
Mumbai - 400054
India 
	
tel: 	91-22-56982010 	
 	

	 	
	
	
 <https://www.plaxo.com/add_me?u=25769950220&v0=291241&k0=719474838> 	
 


------_=_NextPart_001_01C42D37.10966740
Content-Type: text/html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<TITLE>Message</TITLE>

<META content="MSHTML 6.00.2800.1400" name=GENERATOR></HEAD>
<BODY>
<DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT>&nbsp;</DIV>
<DIV><SPAN class=890484515-28042004><FONT face=Arial color=#0000ff size=2>Just a 
hunch, I needed parentheses.&nbsp; Instead of </FONT></SPAN></DIV>
<DIV><SPAN class=890484515-28042004><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=890484515-28042004><FONT face=Verdana color=#0000ff 
size=2>$oQueryStatus = $oPincodeLayer-&gt;queryByAttributes("OUT_CODE", 
"\"".$szPincode."\"",MS_SINGLE);</FONT><BR></SPAN></DIV>
<DIV><SPAN class=890484515-28042004><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=890484515-28042004><FONT face=Arial color=#0000ff 
size=2>try</FONT></SPAN></DIV>
<DIV><SPAN class=890484515-28042004><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=890484515-28042004><FONT face=Verdana color=#0000ff 
size=2>$oQueryStatus = $oPincodeLayer-&gt;queryByAttributes("OUT_CODE", 
"(\"".$szPincode."\")",MS_SINGLE);</FONT><BR></SPAN></DIV>
<DIV><SPAN class=890484515-28042004><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=890484515-28042004><FONT face=Arial color=#0000ff size=2><SPAN 
class=890294715-28042004>Hope it helps,</SPAN></FONT></SPAN></DIV>
<DIV><SPAN class=890484515-28042004><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=890484515-28042004><FONT face=Arial color=#0000ff 
size=2>Adam</FONT></DIV></SPAN>
<DIV><FONT face=Arial color=#0000ff size=2></FONT>&nbsp;</DIV></DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
  <DIV></DIV>
  <DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left><FONT 
  face=Tahoma size=2>-----Original Message-----<BR><B>From:</B> Satyajit 
  [mailto:satyajit.gantayat at aurovision.com] <BR><B>Sent:</B> Wednesday, April 
  28, 2004 12:39 AM<BR><B>To:</B> 
  mapserver-users at lists.gis.umn.edu<BR><B>Subject:</B> [Mapserver-users] 
  QueryByAttribute<BR><BR></FONT></DIV>
  <DIV><SPAN class=702320412-27042004><FONT face=Verdana><FONT size=2><SPAN 
  class=859083807-28042004><FONT color=#0000ff>&nbsp;</FONT><FONT 
  color=#000000>H</FONT></SPAN>i Folks,</FONT></FONT></SPAN></DIV>
  <BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
    <DIV><FONT face=Verdana size=2><SPAN 
    class=702320412-27042004>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I have been 
    banging&nbsp;my head since a couple of days with this code. I am trying to 
    build an application where the user can search for a specific postcode and 
    then the map will zoom into that particular extent. </SPAN></FONT></DIV>
    <DIV><FONT face=Verdana size=2>&nbsp;When the user enters a p<SPAN 
    class=702320412-27042004>ostcode ( I call it PINCODE) in the 
    inputbox</SPAN><SPAN class=702320412-27042004>&nbsp;</SPAN>we search the 
    pincode in the pincode sh<SPAN class=702320412-27042004>a</SPAN>p<SPAN 
    class=702320412-27042004>e</SPAN> file and set the map's extent to that of 
    the shape found.<BR>But the following code is not working. The 
    queryByAttributes function is reporting MS_FAILURE. This code is some what 
    similar to that in one of the listings.&nbsp;<SPAN 
    class=702320412-27042004>It would beb great if somebody guide 
    me&nbsp;</SPAN><SPAN class=702320412-27042004>through</SPAN> step by step 
    procedure<SPAN class=702320412-27042004> </SPAN>of developing this kind 
    of&nbsp;<SPAN class=702320412-27042004>Q</SPAN>uery<SPAN 
    class=702320412-27042004>B</SPAN>y<SPAN 
    class=702320412-27042004>A</SPAN>ttribute feature using 
    Mapserver.</FONT></DIV>
    <DIV><FONT face=Verdana size=2></FONT>&nbsp;</DIV>
    <DIV><FONT face=Verdana size=2></FONT>&nbsp;</DIV>
    <DIV><FONT face=Verdana color=#0000ff size=2>if 
    ($http_form_vars["Pincode"])<BR>{<BR>&nbsp;// the pincode to query 
    for<BR>&nbsp;$szPincode = 
    $http_form_vars["Pincode"];<BR>&nbsp;<BR>&nbsp;$oPincodeLayer = 
    $oMapSession-&gt;oMap-&gt;getLayerByName("Pincode");<BR>&nbsp;<BR><SPAN 
    class=702320412-27042004>// OUT_CODE is the field name which contains the 
    value&nbsp;which would be queried.</SPAN>&nbsp;</FONT></DIV>
    <DIV><FONT face=Verdana color=#0000ff size=2></FONT>&nbsp;</DIV>
    <DIV><FONT face=Verdana color=#0000ff size=2>$oQueryStatus = 
    $oPincodeLayer-&gt;queryByAttributes("OUT_CODE", 
    "\"".$szPincode."\"",MS_SINGLE);<BR>&nbsp;<BR>&nbsp;if ( $oQueryStatus = 
    MS_FAILURE )<BR>&nbsp;{<BR>&nbsp;&nbsp;echo&nbsp; "&lt;td &gt;&lt;b&gt; 
    Query Failed ... \"".$szPincode."\" 
    &lt;/b&gt;&lt;/td&gt;";<BR>&nbsp;&nbsp;echo "&lt;td&gt; Query Status = 
    ".$oQueryStatus."&lt;/td&gt;";<BR>&nbsp;}<BR>&nbsp;else<BR>&nbsp;{<BR>&nbsp;&nbsp;if 
    ($oPincodeLayer-&gt;getNumResults() &gt; 
    0)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;$oResult = 
    $oPincodeLayer-&gt;getResult(0);<BR>&nbsp;&nbsp;&nbsp;$oOpen = 
    $oPincodeLayer-&gt;open();<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;$oShape 
    = $oPincodeLayer-&gt;getShape($oResult-&gt;tileindex, 
    $oResult-&gt;shapeid);<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;$oExtents 
    = 
    $oShape-&gt;bounds;<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;$oShape-&gt;free();<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp;//at 
    this point we might add a buffer to the extents<BR>&nbsp;&nbsp;&nbsp;$nMinX 
    = $oExtents-&gt;minx;<BR>&nbsp;&nbsp;&nbsp;$nMaxX = 
    $oExtents-&gt;maxx;<BR>&nbsp;&nbsp;&nbsp;$nMinY = 
    $oExtents-&gt;miny;<BR>&nbsp;&nbsp;&nbsp;$nMaxY = 
    $oExtents-&gt;maxy;<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;$oExtents-&gt;setExtent( 
    $nMinX, $nMinY, $nMaxX, $nMaxY );<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;// now use 
    $oMapNavigator to navigate to the parcel<BR>&nbsp;&nbsp;// location.&nbsp; 
    There are two useful options now.&nbsp; We<BR>&nbsp;&nbsp;// can zoom to a 
    rectangle which we have calculated or<BR>&nbsp;&nbsp;// to a point and 
    scale.&nbsp; Let's assume we have calculated<BR>&nbsp;&nbsp;// a rectangle 
    and put a buffer around it if 
    necessary.<BR>&nbsp;&nbsp;//$oMapNavigator-&gt;zoomRectangle($nMinX,&nbsp; 
    $nMinY,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //$nMaxX, 
    $nMaxY);<BR>&nbsp;&nbsp; $oMapSession-&gt;oMap-&gt;setExtent( 
    $oExtents-&gt;minx, $oExtents-&gt;miny, $oExtents-&gt;maxx, 
    $oExtents-&gt;maxy );<BR>&nbsp;}<BR>}</FONT></DIV>
    <DIV><FONT face=Verdana size=2></FONT>&nbsp;</DIV>
    <DIV><BR><FONT face=Verdana><FONT size=2>&nbsp;<SPAN 
    class=702320412-27042004>I am using</SPAN></FONT></FONT></DIV>
    <DIV><FONT face=Verdana><FONT size=2><SPAN 
    class=702320412-27042004>&nbsp;&nbsp;&nbsp; MapServer/MapScript 
    4.0</SPAN></FONT></FONT></DIV>
    <DIV><FONT face=Verdana><FONT size=2><SPAN 
    class=702320412-27042004>&nbsp;&nbsp;&nbsp; PHP 
    4.3</SPAN></FONT></FONT></DIV>
    <DIV><FONT face=Verdana><FONT size=2><SPAN 
    class=702320412-27042004>&nbsp;&nbsp;&nbsp; MapLab 
    2.1</SPAN></FONT></FONT></DIV>
    <DIV><FONT face=Verdana><FONT size=2><SPAN 
    class=702320412-27042004>&nbsp;&nbsp;&nbsp;</SPAN></FONT></FONT></DIV>
    <DIV><FONT face=Verdana><FONT size=2><SPAN 
    class=702320412-27042004></SPAN></FONT></FONT>&nbsp;</DIV>
    <DIV><FONT face=Verdana><FONT size=2><SPAN class=702320412-27042004>Thanks 
    and Regards</SPAN></FONT></FONT></DIV>
    <DIV><FONT face=Verdana><FONT size=2><SPAN class=702320412-27042004>Satyajit 
    G.</SPAN></FONT></FONT></DIV>
    <DIV><FONT face=Verdana><FONT size=2><SPAN 
    class=702320412-27042004>&nbsp;&nbsp;&nbsp; </SPAN></FONT></FONT></DIV>
    <DIV><FONT face=Verdana size=2></FONT>&nbsp;</DIV>
    <STYLE>A.psl {
	COLOR: #4e81c4; TEXT-DECORATION: none
}
A:hover {
	TEXT-DECORATION: underline
}
A.psl:hover {
	COLOR: #999999
}
.noro {
	FONT-SIZE: 8pt; COLOR: #4e81c4; FONT-FAMILY: Verdana,Arial,fixed
}
.tiny {
	FONT-SIZE: 1pt
}
.logotext {
	FONT-SIZE: 10pt; FONT-FAMILY: Verdana,Arial,fixed; TEXT-DECORATION: none
}
A.brand {
	FONT-SIZE: 7pt; COLOR: #777777; FONT-FAMILY: Verdana,Arial,fixed; TEXT-DECORATION: none
}
</STYLE>

    <DIV align=left>
    <TABLE cellSpacing=0 cellPadding=0 width=320 border=0>
      <TBODY>
      <TR>
        <TD>
          <TABLE height=80 cellSpacing=0 cellPadding=0 width=320 align=right 
          border=0>
            <TBODY>
            <TR>
              <TD class=tiny>
                <TABLE 
                style="BORDER-RIGHT: #666666 1px solid; BORDER-TOP: #666666 1px solid; BORDER-LEFT: #666666 1px solid; BORDER-BOTTOM: #666666 1px solid" 
                height="100%" cellSpacing=0 width=320>
                  <TBODY>
                  <TR bgColor=#ffffff>
                    <TD class=tiny width="100%" height=1>
                      <TABLE cellSpacing=0 cellPadding=1 width="100%" 
                        border=0><TBODY>
                        <TR>
                          <TD class=logotext style="PADDING-LEFT: 5px"></TD>
                          <TD class=noro 
                          style="PADDING-RIGHT: 5px; FONT-SIZE: 7pt" 
                            align=right><FONT size=1>Imaging the way ahead 
                            ...</FONT></TD></TR></TBODY></TABLE></TD>
                    <TD class=tiny></TD></TR>
                  <TR>
                    <TD colSpan=2>
                      <TABLE style="WIDTH: 358px; HEIGHT: 113px" height=113 
                      cellSpacing=2 width=358 align=right border=0>
                        <TBODY>
                        <TR style="PADDING-BOTTOM: 4px" height=1>
                          <TD class=noro style="PADDING-LEFT: 4px" 
                            vAlign=top><FONT size=2><B>Satyajit 
                            Gantayat</B><BR><FONT face=v><EM>Sr. Specialist 
                            GIS</EM></FONT></FONT> </TD>
                          <TD class=noro style="PADDING-RIGHT: 4px" vAlign=top 
                          align=right>
                            <DIV><FONT size=2><B>Aurovision Pvt. 
                            Ltd.</B><BR>101, Swati<BR>North Avenue<BR>Santacuz 
                            (w)<BR>Mumbai - 400054</FONT></DIV>
                            <DIV><FONT size=2>India&nbsp;</FONT></DIV></TD></TR>
                        <TR height=1>
                          <TD class=noro 
                          style="PADDING-LEFT: 4px; PADDING-BOTTOM: 4px" 
                          vAlign=bottom><FONT size=2></FONT></TD>
                          <TD class=noro 
                          style="PADDING-RIGHT: 4px; PADDING-BOTTOM: 4px" 
                          vAlign=bottom align=right>
                            <TABLE cellSpacing=0 align=right border=0>
                              <TBODY>
                              <TR>
                                <TD class=noro noWrap align=right><FONT 
                                size=2>tel: </FONT></TD>
                                <TD class=noro style="PADDING-LEFT: 4px" noWrap 
                                align=right><FONT size=2>91-22-56982010</FONT> 
                                </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD>
              <TD style="BACKGROUND-REPEAT: repeat-y" vAlign=top width=6 
              background=http://www.plaxo.com/images/card_shadow2_right_middle.gif 
              height="100%">
                <TABLE cellSpacing=0 cellPadding=0 border=0>
                  <TBODY>
                  <TR>
                    <TD style="BACKGROUND-REPEAT: no-repeat" width=6 
                    background=http://www.plaxo.com/images/card_shadow2_right_top.gif 
                    height=7>&nbsp;</TD></TR></TBODY></TABLE></TD></TR>
            <TR>
              <TD class=tiny style="BACKGROUND-REPEAT: repeat-x" 
              background=http://www.plaxo.com/images/card_shadow2_bottom_middle.gif>
                <TABLE class=tiny cellSpacing=0 cellPadding=0 width="100%" 
                align=right border=0>
                  <TBODY>
                  <TR>
                    <TD class=tiny style="BACKGROUND-REPEAT: no-repeat" 
                    vAlign=top width=8 
                    background=http://www.plaxo.com/images/card_shadow2_bottom_left.gif 
                    height=6></TD>
                    <TD class=tiny style="BACKGROUND-REPEAT: repeat-x" 
                    vAlign=top 
                    background=http://www.plaxo.com/images/card_shadow2_bottom_middle.gif 
                    height=6>&nbsp;</TD></TR></TBODY></TABLE></TD>
              <TD class=tiny style="BACKGROUND-REPEAT: no-repeat" vAlign=top 
              width=7 
              background=http://www.plaxo.com/images/card_shadow2_bottom_right_corner.gif 
              height=6></TD></TR></TBODY></TABLE></TD></TR>
      <TR>
        <TD class=tiny colSpan=2></TD></TR>
      <TR>
        <TD align=middle colSpan=2><FONT face=Verdana size=2></FONT><A 
          class=brand 
          href="https://www.plaxo.com/add_me?u=25769950220&amp;v0=291241&amp;k0=719474838" 
          target=_blank><I></I></A></TD></TR></TBODY></TABLE></DIV>
    <DIV>&nbsp;</DIV></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>

------_=_NextPart_001_01C42D37.10966740--



More information about the mapserver-users mailing list