[Mapserver-users] QueryByAttribute

Satyajit satyajit.gantayat at aurovision.com
Wed Apr 28 03:38:50 EDT 2004


This is a multi-part message in MIME format.

------=_NextPart_000_0010_01C42D21.F7855E60
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

 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_000_0010_01C42D21.F7855E60
Content-Type: text/html;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

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

<META content=3D"MSHTML 6.00.2800.1106" name=3DGENERATOR></HEAD>
<BODY>
<DIV><SPAN class=3D702320412-27042004><FONT face=3DVerdana><FONT =
size=3D2><SPAN=20
class=3D859083807-28042004><FONT color=3D#0000ff>&nbsp;</FONT><FONT=20
color=3D#000000>H</FONT></SPAN>i Folks,</FONT></FONT></SPAN></DIV>
<BLOCKQUOTE dir=3Dltr style=3D"MARGIN-RIGHT: 0px">
  <DIV><FONT face=3DVerdana size=3D2><SPAN=20
  class=3D702320412-27042004>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I have =
been=20
  banging&nbsp;my head since a couple of days with this code. I am =
trying to=20
  build an application where the user can search for a specific postcode =
and=20
  then the map will zoom into that particular extent. =
</SPAN></FONT></DIV>
  <DIV><FONT face=3DVerdana size=3D2>&nbsp;When the user enters a p<SPAN =

  class=3D702320412-27042004>ostcode ( I call it PINCODE) in the=20
  inputbox</SPAN><SPAN class=3D702320412-27042004>&nbsp;</SPAN>we search =
the=20
  pincode in the pincode sh<SPAN =
class=3D702320412-27042004>a</SPAN>p<SPAN=20
  class=3D702320412-27042004>e</SPAN> file and set the map's extent to =
that of the=20
  shape found.<BR>But the following code is not working. The =
queryByAttributes=20
  function is reporting MS_FAILURE. This code is some what similar to =
that in=20
  one of the listings.&nbsp;<SPAN class=3D702320412-27042004>It would =
beb great if=20
  somebody guide me&nbsp;</SPAN><SPAN =
class=3D702320412-27042004>through</SPAN>=20
  step by step procedure<SPAN class=3D702320412-27042004> </SPAN>of =
developing=20
  this kind of&nbsp;<SPAN class=3D702320412-27042004>Q</SPAN>uery<SPAN=20
  class=3D702320412-27042004>B</SPAN>y<SPAN=20
  class=3D702320412-27042004>A</SPAN>ttribute feature using=20
Mapserver.</FONT></DIV>
  <DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DVerdana color=3D#0000ff size=3D2>if=20
  ($http_form_vars["Pincode"])<BR>{<BR>&nbsp;// the pincode to query=20
  for<BR>&nbsp;$szPincode =3D=20
  $http_form_vars["Pincode"];<BR>&nbsp;<BR>&nbsp;$oPincodeLayer =3D=20
  =
$oMapSession-&gt;oMap-&gt;getLayerByName("Pincode");<BR>&nbsp;<BR><SPAN=20
  class=3D702320412-27042004>// OUT_CODE is the field name which =
contains the=20
  value&nbsp;which would be queried.</SPAN>&nbsp;</FONT></DIV>
  <DIV><FONT face=3DVerdana color=3D#0000ff size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DVerdana color=3D#0000ff size=3D2>$oQueryStatus =3D=20
  $oPincodeLayer-&gt;queryByAttributes("OUT_CODE",=20
  "\"".$szPincode."\"",MS_SINGLE);<BR>&nbsp;<BR>&nbsp;if ( $oQueryStatus =
=3D=20
  MS_FAILURE )<BR>&nbsp;{<BR>&nbsp;&nbsp;echo&nbsp; "&lt;td =
&gt;&lt;b&gt; Query=20
  Failed ... \"".$szPincode."\" =
&lt;/b&gt;&lt;/td&gt;";<BR>&nbsp;&nbsp;echo=20
  "&lt;td&gt; Query Status =3D=20
  =
".$oQueryStatus."&lt;/td&gt;";<BR>&nbsp;}<BR>&nbsp;else<BR>&nbsp;{<BR>&nb=
sp;&nbsp;if=20
  ($oPincodeLayer-&gt;getNumResults() &gt;=20
  0)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;$oResult =3D=20
  $oPincodeLayer-&gt;getResult(0);<BR>&nbsp;&nbsp;&nbsp;$oOpen =3D=20
  =
$oPincodeLayer-&gt;open();<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;$oS=
hape=20
  =3D $oPincodeLayer-&gt;getShape($oResult-&gt;tileindex,=20
  =
$oResult-&gt;shapeid);<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;$oExten=
ts =3D=20
  =
$oShape-&gt;bounds;<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;$oShape-&g=
t;free();<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp;//at=20
  this point we might add a buffer to the =
extents<BR>&nbsp;&nbsp;&nbsp;$nMinX =3D=20
  $oExtents-&gt;minx;<BR>&nbsp;&nbsp;&nbsp;$nMaxX =3D=20
  $oExtents-&gt;maxx;<BR>&nbsp;&nbsp;&nbsp;$nMinY =3D=20
  $oExtents-&gt;miny;<BR>&nbsp;&nbsp;&nbsp;$nMaxY =3D=20
  =
$oExtents-&gt;maxy;<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;$oExtents-=
&gt;setExtent(=20
  $nMinX, $nMinY, $nMaxX, $nMaxY );<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;// =
now use=20
  $oMapNavigator to navigate to the parcel<BR>&nbsp;&nbsp;// =
location.&nbsp;=20
  There are two useful options now.&nbsp; We<BR>&nbsp;&nbsp;// can zoom =
to a=20
  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=20
  put a buffer around it if=20
  =
necessary.<BR>&nbsp;&nbsp;//$oMapNavigator-&gt;zoomRectangle($nMinX,&nbsp=
;=20
  $nMinY,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //$nMaxX,=20
  $nMaxY);<BR>&nbsp;&nbsp; $oMapSession-&gt;oMap-&gt;setExtent(=20
  $oExtents-&gt;minx, $oExtents-&gt;miny, $oExtents-&gt;maxx, =
$oExtents-&gt;maxy=20
  );<BR>&nbsp;}<BR>}</FONT></DIV>
  <DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
  <DIV><BR><FONT face=3DVerdana><FONT size=3D2>&nbsp;<SPAN=20
  class=3D702320412-27042004>I am using</SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DVerdana><FONT size=3D2><SPAN=20
  class=3D702320412-27042004>&nbsp;&nbsp;&nbsp; MapServer/MapScript=20
  4.0</SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DVerdana><FONT size=3D2><SPAN=20
  class=3D702320412-27042004>&nbsp;&nbsp;&nbsp; PHP =
4.3</SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DVerdana><FONT size=3D2><SPAN=20
  class=3D702320412-27042004>&nbsp;&nbsp;&nbsp; MapLab=20
  2.1</SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DVerdana><FONT size=3D2><SPAN=20
  =
class=3D702320412-27042004>&nbsp;&nbsp;&nbsp;</SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DVerdana><FONT size=3D2><SPAN=20
  class=3D702320412-27042004></SPAN></FONT></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DVerdana><FONT size=3D2><SPAN =
class=3D702320412-27042004>Thanks and=20
  Regards</SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DVerdana><FONT size=3D2><SPAN =
class=3D702320412-27042004>Satyajit=20
  G.</SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DVerdana><FONT size=3D2><SPAN=20
  class=3D702320412-27042004>&nbsp;&nbsp;&nbsp; =
</SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DVerdana size=3D2></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=3Dleft>
  <TABLE cellSpacing=3D0 cellPadding=3D0 width=3D320 border=3D0>
    <TBODY>
    <TR>
      <TD>
        <TABLE height=3D80 cellSpacing=3D0 cellPadding=3D0 width=3D320 =
align=3Dright=20
        border=3D0>
          <TBODY>
          <TR>
            <TD class=3Dtiny>
              <TABLE=20
              style=3D"BORDER-RIGHT: #666666 1px solid; BORDER-TOP: =
#666666 1px solid; BORDER-LEFT: #666666 1px solid; BORDER-BOTTOM: =
#666666 1px solid"=20
              height=3D"100%" cellSpacing=3D0 width=3D320>
                <TBODY>
                <TR bgColor=3D#ffffff>
                  <TD class=3Dtiny width=3D"100%" height=3D1>
                    <TABLE cellSpacing=3D0 cellPadding=3D1 =
width=3D"100%" border=3D0>
                      <TBODY>
                      <TR>
                        <TD class=3Dlogotext style=3D"PADDING-LEFT: =
5px"></TD>
                        <TD class=3Dnoro=20
                        style=3D"PADDING-RIGHT: 5px; FONT-SIZE: 7pt"=20
                          align=3Dright><FONT size=3D1>Imaging the way =
ahead=20
                          ...</FONT></TD></TR></TBODY></TABLE></TD>
                  <TD class=3Dtiny></TD></TR>
                <TR>
                  <TD colSpan=3D2>
                    <TABLE style=3D"WIDTH: 358px; HEIGHT: 113px" =
height=3D113=20
                    cellSpacing=3D2 width=3D358 align=3Dright =
border=3D0>
                      <TBODY>
                      <TR style=3D"PADDING-BOTTOM: 4px" height=3D1>
                        <TD class=3Dnoro style=3D"PADDING-LEFT: 4px"=20
                          vAlign=3Dtop><FONT size=3D2><B>Satyajit=20
                          Gantayat</B><BR><FONT face=3Dv><EM>Sr. =
Specialist=20
                          GIS</EM></FONT></FONT> </TD>
                        <TD class=3Dnoro style=3D"PADDING-RIGHT: 4px" =
vAlign=3Dtop=20
                        align=3Dright>
                          <DIV><FONT size=3D2><B>Aurovision Pvt. =
Ltd.</B><BR>101,=20
                          Swati<BR>North Avenue<BR>Santacuz =
(w)<BR>Mumbai -=20
                          400054</FONT></DIV>
                          <DIV><FONT =
size=3D2>India&nbsp;</FONT></DIV></TD></TR>
                      <TR height=3D1>
                        <TD class=3Dnoro=20
                        style=3D"PADDING-LEFT: 4px; PADDING-BOTTOM: 4px" =

                        vAlign=3Dbottom><FONT size=3D2></FONT></TD>
                        <TD class=3Dnoro=20
                        style=3D"PADDING-RIGHT: 4px; PADDING-BOTTOM: =
4px"=20
                        vAlign=3Dbottom align=3Dright>
                          <TABLE cellSpacing=3D0 align=3Dright =
border=3D0>
                            <TBODY>
                            <TR>
                              <TD class=3Dnoro noWrap =
align=3Dright><FONT=20
                                size=3D2>tel: </FONT></TD>
                              <TD class=3Dnoro style=3D"PADDING-LEFT: =
4px" noWrap=20
                              align=3Dright><FONT =
size=3D2>91-22-56982010</FONT>=20
                              =
</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY></T=
ABLE></TD>
            <TD style=3D"BACKGROUND-REPEAT: repeat-y" vAlign=3Dtop =
width=3D6=20
            =
background=3Dhttp://www.plaxo.com/images/card_shadow2_right_middle.gif=20
            height=3D"100%">
              <TABLE cellSpacing=3D0 cellPadding=3D0 border=3D0>
                <TBODY>
                <TR>
                  <TD style=3D"BACKGROUND-REPEAT: no-repeat" width=3D6=20
                  =
background=3Dhttp://www.plaxo.com/images/card_shadow2_right_top.gif=20
                  height=3D7>&nbsp;</TD></TR></TBODY></TABLE></TD></TR>
          <TR>
            <TD class=3Dtiny style=3D"BACKGROUND-REPEAT: repeat-x"=20
            =
background=3Dhttp://www.plaxo.com/images/card_shadow2_bottom_middle.gif>
              <TABLE class=3Dtiny cellSpacing=3D0 cellPadding=3D0 =
width=3D"100%"=20
              align=3Dright border=3D0>
                <TBODY>
                <TR>
                  <TD class=3Dtiny style=3D"BACKGROUND-REPEAT: =
no-repeat" vAlign=3Dtop=20
                  width=3D8=20
                  =
background=3Dhttp://www.plaxo.com/images/card_shadow2_bottom_left.gif=20
                  height=3D6></TD>
                  <TD class=3Dtiny style=3D"BACKGROUND-REPEAT: repeat-x" =
vAlign=3Dtop=20
                  =
background=3Dhttp://www.plaxo.com/images/card_shadow2_bottom_middle.gif=20
                  height=3D6>&nbsp;</TD></TR></TBODY></TABLE></TD>
            <TD class=3Dtiny style=3D"BACKGROUND-REPEAT: no-repeat" =
vAlign=3Dtop=20
            width=3D7=20
            =
background=3Dhttp://www.plaxo.com/images/card_shadow2_bottom_right_corner=
.gif=20
            height=3D6></TD></TR></TBODY></TABLE></TD></TR>
    <TR>
      <TD class=3Dtiny colSpan=3D2></TD></TR>
    <TR>
      <TD align=3Dmiddle colSpan=3D2><FONT face=3DVerdana =
size=3D2></FONT><A=20
        class=3Dbrand=20
        =
href=3D"https://www.plaxo.com/add_me?u=3D25769950220&amp;v0=3D291241&amp;=
k0=3D719474838"=20
        target=3D_blank><I></I></A></TD></TR></TBODY></TABLE></DIV>
  <DIV>&nbsp;</DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0010_01C42D21.F7855E60--




More information about the mapserver-users mailing list