[MapServer Error]: msQueryByPoint(): No matching record(s) found. /OGR/MYSQL

Fawcett, David David.Fawcett at STATE.MN.US
Mon May 8 10:22:48 EDT 2006


Grabiel, 

My guess on the reason for no responses to your question is that there
are not a lot of people using MySQL in joins in MapServer.  Even fewer
in MapScript.  

I recently wrote a HowTo on using a direct connection to MySQL for a
point data layer.  This method uses MySQL for both the spatial data and
the attribute data.  No shapefile needed.  

This method may work for you.  The HowTo is at:
http://mapserver.gis.umn.edu/docs/howto/ogrmysql

David.

-----Original Message-----
From: UMN MapServer Users List [mailto:MAPSERVER-USERS at LISTS.UMN.EDU] On
Behalf Of grabiel
Sent: Monday, May 08, 2006 5:58 AM
To: MAPSERVER-USERS at LISTS.UMN.EDU
Subject: [UMN_MAPSERVER-USERS] [MapServer Error]: msQueryByPoint(): No
matching record(s) found. /OGR/MYSQL



 Hi
   I have posted one message for ogr/mysql problem(No reply so far). If
anyone has implemented ogr/mysql/php Plz. help me out. What i am trying
is to relate a shape file with mysql table. I can able to fetch the data
through ogrinfo in command line which is like this--->
   
[root at localhost bin]ogrinfo
/usr/local/apache/htdocs/gmap/htdocs/data/n_state.shp -sql "SELECT
st_nm, nsdata.name,nsdata.capital,nsdata.id from n_state LEFT JOIN
'MYSQL:test,host=localhost,user=root,tables=nsdata'.nsdata ON
n_state.st_nm=nsdata.name"

The command above woks fine but when i try the same from mapfile, I am
getting the following error. 
>Warning: [MapServer Error]: msQueryByPoint(): No matching record(s) 
>found.
>in /usr/local/apache/htdocs/gmap/htdocs/gmap75.inc.php on line 425
 
 The error above is only for the layer where i have used OGR/MySql
table, whereas for layers where i havenot used OGR/MySql(simply shape
file & Metadata) its showing the results.
     
My mapfile code for ogr is something like this--> 
................
................
 
  LAYER
    NAME "n_state"
    TYPE POINT
    CONNECTIONTYPE OGR
   CONNECTION "/usr/local/apache/htdocs/gmap/htdocs/data/n_state.shp"
    DATA "SELECT * from n_state left join
'MYSQL:test,host=localhost,user=root,tables=nsdata'.nsdata ON
n_state.st_nm=nsdata.name"
    STATUS ON
    CLASSITEM "st_nm"
    CLASS
        NAME "NEIGHBOURING STATE"
        EXPRESSION /A*/ 
        COLOR 255 0 0
        OUTLINECOLOR 255 0 0
        SYMBOL "NS"
    END
END

..........
..........      

I have given the mapfile(.map) and Php code(.php) in two files below for
better understanding.
 
 If anyone has implemented this by PHP plz share your ideas/experience
for the query part. Maybe something went terribly wrong in my
PHP/Mapscript(I assume). In detail explanation for Php/mapscript will
really be appreciated.
 
Expecting some reply this time(What time!!!) 
Thanks in advance
With regards
 
MAP FILE:
*********
NAME "test"
SIZE 400 400
STATUS ON
SYMBOLSET "DATA/symbols.sym"
EXTENT 27000.860 2462.020 3582.801 3012.468
UNITS METERS
.................
.................
................
QUERYMAP
  STYLE HILITE
  COLOR 255 0 0
  STATUS ON
END

 
LAYER
    NAME "TEST"
     METADATA
         ..........
         ..........       
     END  
    TYPE POINT
    STATUS ON
    DATA "TEST"
    CLASS
        NAME "CITY"
        COLOR 26 37 255
        OUTLINECOLOR 120 120 120
        TEMPLATE "ttt_query.html"	
	STYLE
            COLOR 110 50 100
            OUTLINECOLOR 200 200 200
            SYMBOL 0
        END
    END
END

LAYER
    NAME "n_state"
    TYPE POINT
    CONNECTIONTYPE OGR
    CONNECTION "/usr/local/apache/htdocs/gmap/htdocs/data/n_state.shp"
    DATA "SELECT * from n_state left join
'MYSQL:test,host=localhost,user=root,tables=nsdata'.nsdata ON
n_state.st_nm=nsdata.name"
    STATUS ON
    CLASSITEM "st_nm"
    CLASS
        NAME "NEIGHBOURING STATE"
        EXPRESSION /A*/ 
        COLOR 255 0 0
        OUTLINECOLOR 255 0 0
        SYMBOL "NS"
    END
END

  
END
************* END OF MAP FILE********************
************* START OF PHP FILE ***************
<?php

if (sizeof($HTTP_POST_VARS) > 0)
  $HTTP_FORM_VARS = $HTTP_POST_VARS;
else if (sizeof($HTTP_GET_VARS) > 0)
  $HTTP_FORM_VARS = $HTTP_GET_VARS;
else
  $HTTP_FORM_VARS = array("");


/* ====================================================================
*/
/* Find out whether GIF is supported... if not falback on PNG/JPG
*/
/* ====================================================================
*/ if (strpos( ms_GetVersion(), "OUTPUT=GIF") > 0 ) {
  $gAppletImgFmt = MS_GIF;
  $gImagesFmt = MS_GIF;
}
else
{ 
  $gAppletImgFmt = MS_JPEG;
  $gImagesFmt = MS_PNG;
}

/***********************************************************************
*/
/*                     function GMap75CheckClick()
*/
/*
*/
/*      Function to set the status ON/OFF of a layer according to
*/
/*      htrtp parameters passed. (paremeters are here equal to the
*/
/*      layer name).
*/
/***********************************************************************
*/
function GMap75CheckClick()
{
    GLOBAL      $HTTP_FORM_VARS;
    GLOBAL      $gpoMap, $gbShowQueryResults, $gszZoomBoxExt;
    GLOBAL      $dfMapExtMinX;
    GLOBAL      $dfMapExtMinY;
    GLOBAL      $dfMapExtMaxX;
    GLOBAL      $dfMapExtMaxY;
    
    GLOBAL      $dfMaxExtMinX;
    GLOBAL      $dfMaxExtMinY;
    GLOBAL      $dfMaxExtMaxX;
    GLOBAL      $dfMaxExtMaxY;
    
    reset( $HTTP_FORM_VARS );
   // $gbShowQueryResults=TRUE;
//    while ( list( $key, $val ) = each( $HTTP_FORM_VARS ) ) 
//    {
//        printf("%s=%s<BR>\n", $key, $val);
//    }

/* --------------------------------------------------------------------
*/
/*      look for all layers set to on/off
*/
/* --------------------------------------------------------------------
*/
    if (sizeof($HTTP_FORM_VARS) >= 2)
    {
        $poLayer = $gpoMap->getlayerbyname(asmroad);	
        if ($HTTP_FORM_VARS["asmroad"])
            $poLayer->set("status", 1);
        else
            $poLayer->set("status", 0);

         $poLayer = $gpoMap->getlayerbyname(newvill);	
        if ($HTTP_FORM_VARS["newvill"])
            $poLayer->set("status", 1);
        else
            $poLayer->set("status", 0);

        $poLayer = $gpoMap->getlayerbyname(n_state);	
        if ($HTTP_FORM_VARS["n_state"])
            $poLayer->set("status", 1);
        else
            $poLayer->set("status", 0);
	    
	 $poLayer = $gpoMap->getlayerbyname(raster_back);	
        if ($HTTP_FORM_VARS["raster_back"])
            $poLayer->set("status", 1);
        else
            $poLayer->set("status", 0);   

        
    }

/* --------------------------------------------------------------------
*/
/*      these are the extents of waht is seen actually, they are
*/
/*      generated in function GMapRedraw().
*/
/* --------------------------------------------------------------------
*/
    if ($HTTP_FORM_VARS["minx"])
    {
        $dfMinX = doubleval($HTTP_FORM_VARS["minx"]);
        $dfMinY = doubleval($HTTP_FORM_VARS["miny"]);
        $dfMaxX = doubleval($HTTP_FORM_VARS["maxx"]); 
        $dfMaxY = doubleval($HTTP_FORM_VARS["maxy"]);
//        printf("minx\n");
        
    }
    else
    {
        $dfMinX = $gpoMap->extent->minx;
        $dfMinY = $gpoMap->extent->miny;
        $dfMaxX = $gpoMap->extent->maxx;
        $dfMaxY = $gpoMap->extent->maxy;
    }

/* --------------------------------------------------------------------
*/
/*      check for image width, hight changes.
*/
/* --------------------------------------------------------------------
*/
    if ($HTTP_FORM_VARS["MapSize"])
    {
        if (ereg("([0-9]+),([0-9]+)",
                 $HTTP_FORM_VARS["MapSize"], $MapSizeExtents))
        {
            $dfWidthPix = intval($MapSizeExtents[1]);
            $dfHeightPix = intval($MapSizeExtents[2]);
 
            $gpoMap->set("width",$dfWidthPix);
            $gpoMap->set("height",$dfHeightPix);
            
            SetMapExtents($dfMinX, $dfMinY, $dfMaxX, $dfMaxY);
        }
    }
  
/* --------------------------------------------------------------------
*/
/*      check if the key map has been cliked.
*/
/* --------------------------------------------------------------------
*/
    if ($HTTP_FORM_VARS["KEYMAP_x"])
    {
/* --------------------------------------------------------------------
*/
/*      initilalize the georef extents of the key map.
*/
/* --------------------------------------------------------------------
*/
        $dfKeyMapXMin = $gpoMap->reference->extent->minx;
        $dfKeyMapYMin = $gpoMap->reference->extent->miny;
        $dfKeyMapXMax = $gpoMap->reference->extent->maxx;
        $dfKeyMapYMax = $gpoMap->reference->extent->maxy;
    
//        printf("dfkeyxmin %f<BR>\n",$dfKeyMapXMin);
//        printf("dfkeyymin %f<BR>\n",$dfKeyMapYMin);
//        printf("dfkeyxmax %f<BR>\n",$dfKeyMapXMax);
//        printf("dfkeyymax %f<BR>\n",$dfKeyMapYMax);

        $nClickPixX = intval($HTTP_FORM_VARS[KEYMAP_x]);
        $nClickPixY = intval($HTTP_FORM_VARS[KEYMAP_y]);
        
        $dfWidthPix = doubleval($HTTP_FORM_VARS[KEYMAPXSIZE]);
        $dfHeightPix = doubleval($HTTP_FORM_VARS[KEYMAPYSIZE]);
        
        $nClickGeoX = GMapPix2Geo($nClickPixX, 0, $dfWidthPix,
$dfKeyMapXMin, 
                                   $dfKeyMapXMax, 0);
        $nClickGeoY = GMapPix2Geo($nClickPixY, 0, $dfHeightPix,
$dfKeyMapYMin, 
                                  $dfKeyMapYMax, 1);

        $dfDeltaX = $dfMaxX - $dfMinX;
        $dfDeltaY = $dfMaxY - $dfMinY;
        $dfMiddleX = $nClickGeoX; 
        $dfMiddleY = $nClickGeoY;

        $dfNewMinX = $dfMiddleX - ($dfDeltaX/2);
        $dfNewMinY = $dfMiddleY - ($dfDeltaY/2);
        $dfNewMaxX = $dfMiddleX + ($dfDeltaX/2);
        $dfNewMaxY = $dfMiddleY + ($dfDeltaY/2);

/* --------------------------------------------------------------------
*/
/*      not go outside the borders.
*/
/* --------------------------------------------------------------------
*/
        if ($dfNewMinX < $dfMaxExtMinX)
        {
            $dfNewMinX = $dfMaxExtMinX;
            $dfNewMaxX = $dfNewMinX + ($dfDeltaX);
        }

        if ($dfNewMaxX > $dfMaxExtMaxX)
        {
            $dfNewMaxX = $dfMaxExtMaxX;
            $dfNewMinX = $dfNewMaxX - ($dfDeltaX);
        }
        if ($dfNewMinY < $dfMaxExtMinY)
        {
            $dfNewMinY = $dfMaxExtMinY;
            $dfNewMaxY = $dfNewMinY + ($dfDeltaY);
        }
        if ($dfNewMaxY > $dfMaxExtMaxY)
        {
            $dfNewMaxY = $dfMaxExtMaxY;
            $dfNewMinY = $dfNewMaxY - ($dfDeltaY);
        }
        
        SetMapExtents($dfNewMinX, $dfNewMinY, $dfNewMaxX, $dfNewMaxY);

//      return;
    }
  
/* --------------------------------------------------------------------
*/
/*      province selection.
*/
/* --------------------------------------------------------------------
*/
    if ($HTTP_FORM_VARS["ViewRegion"])
    {
        if (ereg("(-?[0-9]+),(-?[0-9]+),(-?[0-9]+),(-?[0-9]+)",
                 $HTTP_FORM_VARS["ViewRegion"], $ProvExtents))
        {
            $dfMinX = doubleval($ProvExtents[1]);
            $dfMinY = doubleval($ProvExtents[2]);
            $dfMaxX = doubleval($ProvExtents[3]);
            $dfMaxY = doubleval($ProvExtents[4]);

            SetMapExtents($dfMinX, $dfMinY, $dfMaxX, $dfMaxY);
        }
    }

/* --------------------------------------------------------------------
*/
/*      extract the current width and height.
*/
/* --------------------------------------------------------------------
*/
    if ($HTTP_FORM_VARS["imagewidth"])
    {
        $dfWidthPix = intval($HTTP_FORM_VARS["imagewidth"]);
        $dfHeightPix = intval($HTTP_FORM_VARS["imageheight"]);
    }
    else
    {
        $dfWidthPix  = $gpoMap->width;
        $dfHeightPix = $gpoMap->height;
    }


    
/* --------------------------------------------------------------------
*/
/*      check if it the redraw button which is pressed : if it is
*/
/*      the case redraw the same extents.
*/
/* --------------------------------------------------------------------
*/
    if ($HTTP_FORM_VARS["redraw_x"])
    {
        SetMapExtents($dfMinX, $dfMinY, $dfMaxX, $dfMaxY);
    }
/* --------------------------------------------------------------------
*/
/*      Check for zoom out (auto-submit) button.
*/
/* --------------------------------------------------------------------
*/
    else if ($HTTP_FORM_VARS["CMD"] == "ZOOM_OUT" && 
             !($HTTP_FORM_VARS["mainmap_x"] ||
$HTTP_FORM_VARS["INPUT_COORD"]))
    {
        $oPixelPos = ms_newpointobj();
        $oGeorefExt = ms_newrectobj();
        $oGeorefMaxExt = ms_newrectobj();

        $oPixelPos->setxy($dfWidthPix/2.0, $dfHeightPix/2.0);
        $oGeorefExt->setextent($dfMinX, $dfMinY, $dfMaxX, $dfMaxY);
        $oGeorefMaxExt->setextent($dfMaxExtMinX, $dfMaxExtMinY,
                                  $dfMaxExtMaxX, $dfMaxExtMaxY);

        if (!$gpoMap->zoompoint(-2, $oPixelPos, $dfWidthPix,
$dfHeightPix,
                                $oGeorefExt, $oGeorefMaxExt))
        {
            $gpoMap->setExtent($dfMapExtMinX, $dfMapExtMinY, 
                               $dfMapExtMaxX, $dfMapExtMaxY);
        }
    }
/* --------------------------------------------------------------------
*/
/*      check for zoom / query through applet or image click
*/
/* --------------------------------------------------------------------
*/
    else
    {
        $dfDeltaX = $dfMaxX - $dfMinX;
        $dfDeltaY = $dfMaxY - $dfMinY;
	
/* --------------------------------------------------------------------
*/
/*      extract click position.
*/
/*      Convert the click pos to georeref coordinates.
*/
/* --------------------------------------------------------------------
*/
        if ($HTTP_FORM_VARS["mainmap_x"] ||
$HTTP_FORM_VARS["INPUT_TYPE"])
        {
	    $bRectangleInput = 0;
	    if ($HTTP_FORM_VARS["INPUT_TYPE"])
	    {
		$szCoord = strval($HTTP_FORM_VARS["INPUT_COORD"]);
		$szCoordType = strval($HTTP_FORM_VARS["INPUT_TYPE"]);
		if (strcmp($szCoordType,"auto_point") == 0)
		{
		    $szCoordArray =explode(",", $szCoord);
		    $nClickPixX = $szCoordArray[0];
		    $nClickPixY = $szCoordArray[1];
		}
/* --------------------------------------------------------------------
*/
/*      Rosa applet is used and the input is a rectangle
*/
/*      (syntax is X1,Y1;X2,Y2).
*/
/*      If the 2 sets of points are the same treat the case as a
*/
/*      point click.
*/
/* --------------------------------------------------------------------
*/
		else if (strcmp($szCoordType,"auto_rect") == 0)
		{
		    $bRectangleInput = 1;

		    $szFirstSetXY = strtok($szCoord, ";");
		    $szSecondSetXY = strtok("\n");
		    
		    $szFirstCoord = explode(",", $szFirstSetXY);
		    $szSecondCoord = explode(",", $szSecondSetXY);
		    
		    $oPixelRect = ms_newrectobj();
		    
			
		    $oPixelRect->setextent($szFirstCoord[0],
$szFirstCoord[1],
					   $szSecondCoord[0],
$szSecondCoord[1]);

                    if ($oPixelRect->minx ==  $oPixelRect->maxx &&
			$oPixelRect->miny ==  $oPixelRect->maxy)
		    {
			$bRectangleInput = 0;
			$nClickPixX = $oPixelRect->minx;
			$nClickPixY = $oPixelRect->miny;
		    }
		    else
		    {
			if ($oPixelRect->minx >  $oPixelRect->maxx)
			{
                            // Use *1 to avoid dfTmp becoming a
reference
                            // to $oPixelRect->minx with PHP4 !?!?!?
			    $dfTmp = $oPixelRect->minx*1;
			    $oPixelRect->set("minx",$oPixelRect->maxx);
			    $oPixelRect->set("maxx",$dfTmp);
			}
			if ($oPixelRect->miny <  $oPixelRect->maxy)
			{
			    $dfTmp = $oPixelRect->miny*1;
			    $oPixelRect->set("miny", $oPixelRect->maxy);
			    $oPixelRect->set("maxy", $dfTmp);
			}
		    }

                    // We'll insert a copy of the box's georef extent in
a
                    // comment in the HTML output... useful for defining
views.
		    $gszZoomBoxExt = sprintf("<!-- BOX= (%f, %f)-(%f,
%f) -->",
 
GMapPix2Geo($oPixelRect->minx, 0, 
                                                         $dfWidthPix,
$dfMinX, 
                                                         $dfMaxX, 0),
 
GMapPix2Geo($oPixelRect->miny, 0, 
                                                         $dfHeightPix,
$dfMinY,
                                                         $dfMaxY, 1),
 
GMapPix2Geo($oPixelRect->maxx, 0, 
                                                         $dfWidthPix,
$dfMinX, 
                                                         $dfMaxX, 0),
 
GMapPix2Geo($oPixelRect->maxy, 0, 
                                                         $dfHeightPix,
$dfMinY,
                                                         $dfMaxY, 1) );
		}
	    }   
	    else
	    {
		$nClickPixX = intval($HTTP_FORM_VARS[mainmap_x]);
		$nClickPixY = intval($HTTP_FORM_VARS[mainmap_y]);
	    }
            
	    
	    $oPixelPos = ms_newpointobj();
	    $oGeorefExt = ms_newrectobj();
	    $oGeorefMaxExt = ms_newrectobj();

	    $oPixelPos->setxy($nClickPixX, $nClickPixY);
	    $oGeorefExt->setextent($dfMinX, $dfMinY, $dfMaxX, $dfMaxY);
	    $oGeorefMaxExt->setextent($dfMaxExtMinX, $dfMaxExtMinY,
				      $dfMaxExtMaxX, $dfMaxExtMaxY);

            if ($HTTP_FORM_VARS["CMD"] == "ZOOM_IN")
            {
		if ($bRectangleInput)
		{
		    $gpoMap->zoomrectangle($oPixelRect, $dfWidthPix, 
					   $dfHeightPix, $oGeorefExt);
		}
		else
		    $gpoMap->zoompoint(2, $oPixelPos, $dfWidthPix, 
				       $dfHeightPix, $oGeorefExt,
$oGeorefMaxExt);
            }
            if ($HTTP_FORM_VARS["CMD"] == "ZOOM_OUT")
            {
		if (!$gpoMap->zoompoint(-2, $oPixelPos, $dfWidthPix, 
					$dfHeightPix, $oGeorefExt, 
					$oGeorefMaxExt))
		{
		    $gpoMap->setExtent($dfMapExtMinX, $dfMapExtMinY, 
		    		       $dfMapExtMaxX, $dfMapExtMaxY);
		}
	    }
            if ($HTTP_FORM_VARS["CMD"] == "RECENTER")
            {
		$gpoMap->zoompoint(1, $oPixelPos, $dfWidthPix, 
				   $dfHeightPix, $oGeorefExt, 
				   $oGeorefMaxExt);
            }
            else if ($HTTP_FORM_VARS["CMD"] == "QUERY_POINT")
            {
/* --------------------------------------------------------------------
*/
/*      Query selected layers at point location or in a rectangle.
*/
/*      DumpQueryResults() will be called later to display the
*/
/*      results.
*/
/* --------------------------------------------------------------------
*/
		if ($bRectangleInput)
		{	
		    $oGeorefRect = ms_newrectobj();
		    $oGeorefRect->set("minx",
GMapPix2Geo($oPixelRect->minx, 0, 
							  $dfWidthPix,
$dfMinX, 
							  $dfMaxX, 0));
		    $oGeorefRect->set("maxx",
GMapPix2Geo($oPixelRect->maxx, 0, 
							  $dfWidthPix,
$dfMinX, 
							  $dfMaxX, 0));
		    $oGeorefRect->set("miny",
GMapPix2Geo($oPixelRect->miny, 0, 
							  $dfHeightPix,
$dfMinY, 
							  $dfMaxY, 1));
		    $oGeorefRect->set("maxy",
GMapPix2Geo($oPixelRect->maxy, 0, 
							  $dfHeightPix,
$dfMinY, 
							  $dfMaxY, 1));
                    // Use '@' to avoid warning if query found nothing
		    @$gpoMap->queryByRect($oGeorefRect);
                    $gbShowQueryResults = TRUE;
		}
		else
		{
		    $nClickGeoX = GMapPix2Geo($nClickPixX, 0,
$dfWidthPix, 
					      $dfMinX, $dfMaxX, 0);
		    $nClickGeoY = GMapPix2Geo($nClickPixY, 0,
$dfHeightPix, 
					      $dfMinY, $dfMaxY, 1);
		
		    $oClickGeo = ms_newPointObj();
		    $oClickGeo->setXY($nClickGeoX, $nClickGeoY);

                    // Use '@' to avoid warning if query found nothing
		    $gpoMap->queryByPoint($oClickGeo, MS_SINGLE, -1);

                    $gbShowQueryResults = TRUE;
		}
            }
        }
    } 
}		
			
/***********************************************************************
*/
/*                   fuction GMapGetStatus($szLayerName)
*/
/*
*/
/*      return if the layer is on or off (displayed or not) :
*/
/*
*/
/*       ON = MS_ON =1
*/
/*       OFF = MS_OFF = 0
*/
/*
*/
/***********************************************************************
*/
function GMapGetStatus($szLayerName)
{
  GLOBAL $gpoMap;
  
  $poLayer = $gpoMap->getlayerbyname($szLayerName);
  $nStatus = $poLayer->status;

   return ($nStatus);

}
			

/***********************************************************************
*/
/*                        function GMapDrawMap()
*/
/*
*/
/*      Funcion to draw the contains of the map.
*/
/***********************************************************************
*/
function GMapDrawMap()
{
    GLOBAL $gpoMap, $gbShowQueryResults;
    GLOBAL $gbIsHtmlMode;
    GLOBAL $gszCommand, $gszZoomBoxExt;
    GLOBAL $gAppletImgFmt, $gImagesFmt;

    if ($gbShowQueryResults)
    {
        $img = $gpoMap->drawQuery();
    }
    else
        $img = $gpoMap->draw();

    $url = $img->saveWebImage($gAppletImgFmt, 0, 0, -1);

    echo "\n".$gszZoomBoxExt."\n";
    printf("<INPUT TYPE=HIDDEN NAME=minx VALUE=\"%f\">",
$gpoMap->extent->minx);
    printf("<INPUT TYPE=HIDDEN NAME=miny VALUE=\"%f\">",
$gpoMap->extent->miny);
    printf("<INPUT TYPE=HIDDEN NAME=maxx VALUE=\"%f\">",
$gpoMap->extent->maxx);
    printf("<INPUT TYPE=HIDDEN NAME=maxy VALUE=\"%f\">",
$gpoMap->extent->maxy);
	
    printf("<INPUT TYPE=HIDDEN NAME=imagewidth VALUE=\"%d\">",
$gpoMap->width);
    printf("<INPUT TYPE=HIDDEN NAME=imageheight VALUE=\"%d\">",
$gpoMap->height);

/* --------------------------------------------------------------------
*/
/*      Use the command to update the rosa applet.
*/
/* --------------------------------------------------------------------
*/
    if ( strlen($gszCommand) == 0)
    {
	$szButtonName = "zoomin";
    }
    else 
    {
	if ($gszCommand == "ZOOM_IN")
	    $szButtonName = "zoomin";
// Do not keep zoomout pressed ot avoid infinite zoomout loop!!!
//	if ($gszCommand == "ZOOM_OUT")
//	    $szButtonName = "zoomout";
	if ($gszCommand == "RECENTER")
	    $szButtonName = "recentre";
	if ($gszCommand == "QUERY_POINT")
	    $szButtonName = "pquery";
    }
    
    
    if (!$gbIsHtmlMode) //use applet
    {
	printf("\n");
	printf("<APPLET NAME=\"RosaApplet\" ARCHIVE=\"./rosa/rosa.jar\"
CODE=\"Rosa2000\" WIDTH=\"%d\" HEIGHT=\"%d\" MAYSCRIPT>\n",
$gpoMap->width, $gpoMap->height);
	printf("<PARAM NAME=\"TB_POSITION\" VALUE=\"right\">\n");
	printf("<PARAM NAME=\"TB_ALIGN\" VALUE=\"top\">");
	printf("<PARAM NAME=\"IMG_URL\" VALUE=\"%s\">",$url);
	printf("<PARAM NAME=\"INP_FORM_NAME\" VALUE=\"myform\">");
	printf("<PARAM NAME=\"TB_BUTTONS\"
VALUE=\"zoomin|zoomout|recentre|pquery\">\n");
	printf("<PARAM NAME=\"INP_TYPE_NAME\" VALUE=\"INPUT_TYPE\">\n");
	printf("<PARAM NAME=\"INP_COORD_NAME\"
VALUE=\"INPUT_COORD\">\n");

		    
	printf("<PARAM NAME=\"TB_SELECTED_BUTTON\"
VALUE=\"%s\">",$szButtonName);

        printf("<PARAM NAME=\"TB_BUT_zoomin_IMG\"
VALUE=\"./images/tool_zoomin_1.gif\">\n");
	printf("<PARAM NAME=\"TB_BUT_zoomin_IMG_PR\"
VALUE=\"./images/tool_zoomin_2.gif\">\n");
	printf("<PARAM NAME=\"TB_BUT_zoomin_HINT\" VALUE=\"Zoom in:
Click the button|and the map will zoom in\">\n");
        printf("<PARAM NAME=\"TB_BUT_zoomin_INPUT\"
VALUE=\"auto_rect\">\n");
        printf("<PARAM NAME=\"TB_BUT_zoomin_NAME\" VALUE=\"CMD\">\n");
        printf("<PARAM NAME=\"TB_BUT_zoomin_VALUE\"
VALUE=\"ZOOM_IN\">\n");
	
                      
        printf("<PARAM NAME=\"TB_BUT_zoomout_IMG\"
VALUE=\"./images/tool_zoomout_1.gif\">\n");
	printf("<PARAM NAME=\"TB_BUT_zoomout_IMG_PR\"
VALUE=\"./images/tool_zoomout_2.gif\">\n");
	printf("<PARAM NAME=\"TB_BUT_zoomout_HINT\" VALUE=\"Zoom out:
Click the button|and the map will zoom out\">\n");
        printf("<PARAM NAME=\"TB_BUT_zoomout_INPUT\"
VALUE=\"submit\">\n");
        printf("<PARAM NAME=\"TB_BUT_zoomout_NAME\" VALUE=\"CMD\">\n");
        printf("<PARAM NAME=\"TB_BUT_zoomout_VALUE\"
VALUE=\"ZOOM_OUT\">\n");
                                                       
        printf("<PARAM NAME=\"TB_BUT_recentre_IMG\"
VALUE=\"./images/tool_recentre_1.gif\">\n");
	printf("<PARAM NAME=\"TB_BUT_recentre_IMG_PR\"
VALUE=\"./images/tool_recentre_2.gif\">\n");
	printf("<PARAM NAME=\"TB_BUT_recentre_HINT\" VALUE=\"Recenter:
Click the button|and the map will recenter\">\n");
        printf("<PARAM NAME=\"TB_BUT_recentre_INPUT\"
VALUE=\"auto_point\">\n");
        printf("<PARAM NAME=\"TB_BUT_recentre_NAME\" VALUE=\"CMD\">\n");
        printf("<PARAM NAME=\"TB_BUT_recentre_VALUE\"
VALUE=\"RECENTER\">\n");

	printf("<PARAM NAME=\"TB_BUT_pquery_IMG\"
VALUE=\"./images/tool_info_1.gif\">\n");
	printf("<PARAM NAME=\"TB_BUT_pquery_IMG_PR\"
VALUE=\"./images/tool_info_2.gif\">\n");
	printf("<PARAM NAME=\"TB_BUT_pquery_HINT\" VALUE=\"Point Query:
Click a point on the map|for information about that point\">\n");
        printf("<PARAM NAME=\"TB_BUT_pquery_INPUT\"
VALUE=\"auto_rect\">\n");
        printf("<PARAM NAME=\"TB_BUT_pquery_NAME\" VALUE=\"CMD\">\n");
        printf("<PARAM NAME=\"TB_BUT_pquery_VALUE\"
VALUE=\"QUERY_POINT\">\n");

	printf("</APPLET>");
	printf("<INPUT TYPE=\"HIDDEN\" NAME=\"CMD\" VALUE=\"\">");
	printf("<INPUT TYPE=\"HIDDEN\" NAME=\"INPUT_TYPE\"
VALUE=\"\">");
	printf("<INPUT TYPE=\"HIDDEN\" NAME=\"INPUT_COORD\"
VALUE=\"\">");
    }
    else
    {
	echo"<INPUT  TYPE=image SRC=$url  BORDER=0 WIDTH=$gpoMap->width
HEIGHT=$gpoMap->height NAME=mainmap>";
	printf("<INPUT TYPE=\"HIDDEN\" NAME=\"CMD\" VALUE=\"%s\">",
$gszCommand);
    }
//  printf("<IMG SRC=%s WIDTH=%d HEIGHT=%d>\n", $url, $gpoMap->width,
$gpoMap->height);

}

/***********************************************************************
*/
/*                      function GMapDrawKeyMap()
*/
/*
*/
/*      Utility function to draw the refernece map (key map).
*/
/***********************************************************************
*/
function GMapDrawKeyMap()
{
    GLOBAL      $gpoMap;
    GLOBAL $gAppletImgFmt, $gImagesFmt;
	
    $img = $gpoMap->drawreferencemap();
    $url = $img->saveWebImage($gImagesFmt, 0, 0, -1);

    printf("<INPUT TYPE=HIDDEN NAME=KEYMAPXSIZE VALUE=\"%d\">",
$img->width);
    printf("<INPUT TYPE=HIDDEN NAME=KEYMAPYSIZE VALUE=\"%d\">",
$img->height);

//    echo"<IMG  SRC=$url  BORDER=0 >\n";
    echo"<INPUT  TYPE=image SRC=$url  BORDER=0 NAME=KEYMAP>";
}


/***********************************************************************
*/
/*                     function GMapDrawScaleBar()
*/
/*
*/
/*      Draw sacle bar.
*/
/***********************************************************************
*/
function GMapDrawScaleBar()
{
    GLOBAL $gpoMap;
    GLOBAL $gAppletImgFmt, $gImagesFmt;
	
    $img = $gpoMap->drawScaleBar();
    $url = $img->saveWebImage($gImagesFmt, 0, 0, -1);

    echo"<IMG  SRC=$url  BORDER=0 >\n";

}


/***********************************************************************
*/
/*function GMapPix2Geo($nPixPos, $dfPixMin, $dfPixMax, $dfGeoMin,
dfGeoMax,*/
/*                           $nInversePix)
*/
/*
*/
/*      Utility function to convert a pixel position to geocoded
*/
/*      position.
*/
/*
*/
/*       The parameter $nInversePix could be set to 1 for Y pixel
*/
/*      coordinates where the UL > LR. Else set to 0.
*/
/***********************************************************************
*/
function GMapPix2Geo($nPixPos, $dfPixMin, $dfPixMax, $dfGeoMin,
$dfGeoMax, 
                     $nInversePix) 
{
    
//    if ($nPixPos < $dfPixMin)  
//        return -1;

//    if ($nPixPos > $dfPixMax)
//        return -1;

//    if ($dfPixMin >= $dfPixMaX || 
//        $dfGeoMin >= $dfGeoMax)
//        return -1;

    $dfWidthGeo = $dfGeoMax - $dfGeoMin;
    $dfWidthPix = $dfPixMax - $dfPixMin;
   
    
    $dfPixToGeo = $dfWidthGeo / $dfWidthPix;

    if (!$nInversePix)
        $dfDeltaPix = $nPixPos - $dfPixMin;
    else
        $dfDeltaPix = $dfPixMax - $nPixPos;

    $dfDeltaGeo = $dfDeltaPix * $dfPixToGeo;


    $dfPosGeo = $dfGeoMin + $dfDeltaGeo;

    return ($dfPosGeo);
}

/***********************************************************************
*/
/*  function SetMapExtents($dfNewMinX, $dfNewMinY, $dfNewMaxX,
$dfNewMaxY)*/
/*
*/
/*          Set map extents of the map. We also make a test here with
*/
/*          the min/max scale set in the .map file (the web object)
*/
/*          to verify if the extents are respected. If it is the
*/
/*          case return true. Else return false.
*/
/*
*/
/*         Note : the extents of the map are still set using the
*/
/*      parameters passed in argument. The caller has the
*/
/*      responsability to check the return value.
*/
/***********************************************************************
*/
function SetMapExtents($dfNewMinX, $dfNewMinY, $dfNewMaxX, $dfNewMaxY) {
    GLOBAL $gpoMap;
    
    $gpoMap->setExtent($dfNewMinX, $dfNewMinY, $dfNewMaxX, $dfNewMaxY);

    $dfScale = $gpoMap->scale;

//  printf("scale : %f <BR>\n", $dfScale);
//  printf("minscale : %f<BR>\n",$gpoMap->web->minscale);
//  printf("maxscale : %f<BR>\n",$gpoMap->web->maxscale);

    if ($dfScale <  $gpoMap->web->minscale ||
        $dfScale >  $gpoMap->web->maxscale)
        return false;
    
        return true;
}

/***********************************************************************
*/
/*                     function GMapDumpQueryResults()
*/
/*
*/
/*      Produce a table with query results.
*/
/*      Simply prints an " " if there are no query results.        */
/***********************************************************************
*/
function GMapDumpQueryResults()
{
    GLOBAL $gpoMap, $gbShowQueryResults;
    
    
  if (! $gbShowQueryResults )
    {
        printf(" ");
        return;
    }

    $numResultsTotal = 0;

    for($iLayer=0; $iLayer < $gpoMap->numlayers; $iLayer++)
    {
        $oLayer = $gpoMap->GetLayer($iLayer);

        $numResults = $oLayer->getNumResults();
        printf($oLayer.name); 
        if ($numResults == 0)
            continue;  // No results in this layer
        
        // Open layer's table... take the list of fields to display from

        // the "RESULT_FIELDS" metadata in the layer object.
        $oLayer->open();


	//
        // One row in table for each selected record
        //

        for ($iRes=0; $iRes < $numResults; $iRes++)
        {
            $oRes = $oLayer->getResult($iRes);
            
            $oShape =
$oLayer->getShape($oRes->tileindex,$oRes->shapeindex);
            
            if ($iRes == 0)
            {
                //
                // Table header: attribute names...
                //
                if ($oLayer->getMetaData("RESULT_FIELDS"))
                {
                    // Display fields listed in RESULT_FIELDS metadata
                    $selFields = explode(" ",
$oLayer->getMetaData("RESULT_FIELDS"));
                }
                else
                {
                    // RESULT_FIELDS not set. display first 4 fields
                    $i=0;
                    while ( list($key,$val) = each($oShape->values) ) 
                    {
                        $selFields[$i++] = $key;
                        if ($i>=4) break;
                    }
                }

                printf("<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=2
WIDTH=100%%>\n");
                printf("<TR>\n");
                printf("<TD COLSPAN=%d BGCOLOR=#C1D8E3>",
count($selFields));
                printf("<CENTER> %s </CENTER>",
$oLayer->getMetaData("DESCRIPTION"));
                printf("</TD>\n");
                printf("</TR>\n");
                printf("<TR>\n");

                for ($iField=0; $iField < count($selFields); $iField++)
                {
                    printf("<TD BGCOLOR=#E2EFF7>");
                    printf("%s",$selFields[$iField]);
                    printf("</TD>\n");
                }
                printf("</TR>\n");	
            }


            printf("<TR>\n");	

            printf("<!-- bounds(%f, %f)-(%f, %f)-->\n", 
                   $oShape->bounds->minx, $oShape->bounds->miny,
                   $oShape->bounds->maxx, $oShape->bounds->maxy);
//            printf("<!-- ");
//            print_r($oShape);
//            printf(" -->\n");

            for($iField=0; $iField < sizeof($selFields); $iField++)
            {
                printf("<TD BGCOLOR=#FFFFFF>");
                printf("%s", $oShape->values[$selFields[$iField]]);
                printf("</TD>\n");
            }
            printf("</TR>\n");	

            $oShape->free();

            $numResultsTotal++;
        }

        $oLayer->close();

        printf("</TABLE>\n");
    }
    
    
    //printf($oLayer);
    if ($numResultsTotal == 0)
        echo "Nothing at query point.";

}


?>
****************END OF PHP SCRIPT***************************

_______________________________________________
No banners. No pop-ups. No kidding.
Make My Way  your home on the Web - http://www.myway.com



More information about the mapserver-users mailing list