[Mapserver-users] problem with querybyattributes

BAUD remi remi.baud at eivd.ch
Mon Nov 24 12:02:26 EST 2003


Hi the list,
 
I'm trying to select an object from an user input, and then, zooming to it.
I've seen that it was a discussion about it on the list., but when I use this command,
 
$oParcelLayer->queryByAttributes( MS_SINGLE );
 
I got the fellowing message from PHP:
 
Warning: Wrong parameter count for querybyattributes() in C:\ms4w\apps\rossensdemo\htdocs\gmap75.inc.php on line 291
 
I don't see where is the error.
I use php mapscript 40 (this is the gmap sample app.)
The rest of the code is here and works good before querybyattributes.
Could someone help me??
 
begin of the code:
 
 if ($HTTP_FORM_VARS["numparc"])
    {
      
    // the parcel number to query for
    $numparc = $HTTP_FORM_VARS["numparc"];
    settype($numparc, integer);
    printf("numparc : %f <BR>\n", $numparc);
    print "$numparc is a " . gettype($numparc);
    
    // the current extents will be the default if we fail.
   $oExtents = $gpoMap->extent;
   $oldExtents=$oExtents;
    //first we need a handle on the layer, let's assume that we have
   //it's name
    $oLayer = $gpoMap->getlayerbyname("Parcel");
    $oLayer->set("status", 1);
    
    // setting up the filter
    
    $oLayer->set( "filteritem", "NOPARC" );
   $oLayer->setFilter($numparc);
   
   
    // use querybyattribute to generate the result, assume a single
   // one for simplicity but this can be extended to multiple
   // results easily

     $oLayer->queryByAttributes(MS_SINGLE);
    
    //Check if there are any results?
    
    if ($oLayer->getNumResults() > 0 )
 {
  //at least one result, assume only one for this example
  $oResult = $oLayer->getResult( 0 );
  //oResult is a resultCacheMemberObj
  $oLayer->open($gpoMap->shapepath);
  $oShape = $Layer->getShape(
    $oResult->tileindex,$oResult->shapeindex );
  $oExtents = $oShape->bounds;
  $oShape->free();

//at this point we might add a buffer to the extents
  $nXBuffer = ( $oExtents->maxx - $oExtents->minx )*0.05;
  $nYBuffer = ( $oExtents->maxy - $oExtents->miny )*0.05;
  $nMinX = $oExtents->minx - $nXBuffer;
  $nMaxX = $oExtents->maxx + $nXBuffer;
  $nMinY = $oExtents->miny - $nYBuffer;
  $nMaxY = $oExtents->maxy + $nYBuffer;
  $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 use hier a rectangle and a little buffer if necessary.
 
 $width=$gpoMap->width;
 $height=$gpoMap->height;
  $px1=$width/($oldExtents->maxx-$oldExtents->minx)*($oExtents->minx-$oldExtents->minx);
  $px2=$width/($oldExtents->maxx-$oldExtents->minx)*($oExtents->maxx-$oldExtents->minx);
  $py1=$height/($oldExtents->maxy-$oldExtents->miny)*($oldExtents->maxy-$oExtents->maxy);
  $py2=$height/($oldExtents->maxy-$oldExtents->miny)*($oldExtents->maxy-$oExtents->miny);
//printf("numparc : %f <BR>\n", $oResult->shapeindex);
 $gpoMap->zoomRectangle($px1, $py2, $px2, $py1);
 // alternately if it's a point and a scale ...
 //$oMapNavigator->zoomScale( 1000, 100, 100 );
}
 
 




More information about the mapserver-users mailing list