[Mapserver-users] Unique? Was: mapscript - queryByPoint help, simple Q

Lowther, David W dlowther at ou.edu
Fri Aug 29 10:45:31 EDT 2003


That's where my code began - Gmap. Couldn't remember...

<?php
    GLOBAL $gpoMap, $gbShowQueryResults;

	$map_path = "e:\map.map";
	$gpoMap = ms_newMapObj($map_path);

	'I'm submitting a form that has x, y, mapext, and mapsize...
	$click_x = $_POST["x"];
	$click_y = $_POST["y"];
	$me = $_POST["mapext"];
	$mapsize = $_POST["mapsize"];

	$msArray = explode(" ", $mapsize);
	$mapwidth = $msArray[0];
	$mapheight = $msArray[1];

	$current_extent = explode(" ",$me);

	$x_pct = ($click_x / $mapwidth);
	$y_pct = 1 - ($click_y / $mapheight);
	
	$nClickGeoX = $current_extent[0] + ( ($current_extent[2] -
$current_extent[0]) * $x_pct);
	$nClickGeoY = $current_extent[1] + ( ($current_extent[3] -
$current_extent[1]) * $y_pct);


	'// I have to do this because my mapfile is projected to albers, but
my shapefiles are lat lon...
	$extRect = ms_newRectObj();
	
$extRect->SetExtent($nClickGeoX,$nClickGeoY,$nClickGeoX+0.0001,$nClickGeoY+0
.0001);
	$oClickGeo = ms_newPointObj();
	$oClickGeo->setXY($extRect->minx,$extRect->miny);
	$projOutObj = ms_newprojectionobj("proj=latlong,ellps=GRS80");
	$projInObj =
ms_newprojectionobj("proj=aea,ellps=GRS80,datum=NAD83,lat_0=23,lon_0=-96,lat
_1=29.5,lat_2=45.5,x_0=0,y_0=0");
	$newRect = $extRect->project($projInObj, $projOutObj);

	print "<form method=post name=results action=something>\n";
	print "<input type=hidden name=LAT value=".$extRect->miny.">\n";

	print "<input type=hidden name=LON value=".$extRect->minx.">\n";



	// Use '@' to avoid warning if query found nothing
	$oLayer = $gpoMap->GetLayerByName("huc8");
	$oLayer->set("status",MS_ON);

	@$gpoMap->queryByPoint($oClickGeo, MS_MULTIPLE, 20);

	$gbShowQueryResults = TRUE;


    GLOBAL $gpoMap, $gbShowQueryResults;

    if (! $gbShowQueryResults )
    {
        printf("&nbsp;");
        return;
    }

    $numResultsTotal = 0;



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

        if ($numResults == 0)
            continue;  // No results in this layer

        $oLayer->open();


	'//this only writes data for the fields in each layers metadata
"RESULT_FIELDS"
        $selFields = explode(" ", $oLayer->getMetaData("RESULT_FIELDS"));
            
        for ($iRes=0; $iRes < $numResults; $iRes++)
        {
            $oRes = $oLayer->getResult($iRes);

            $oShape = $oLayer->getShape($oRes->tileindex,$oRes->shapeindex);

            for($iField=0; $iField < sizeof($selFields); $iField++)
            {
				print "<input type=hidden
name=".$selFields[$iField]."
value=\"".$oShape->values[$selFields[$iField]]."\">\n";
            }
            $oShape->free();
            $numResultsTotal++;
        }
        $oLayer->close();
    }
	print "</form>\n";
?>

Heres the Layer in the mapfile...

### HUC8 ###
LAYER
	NAME huc8
	GROUP "Bio Survey"
	TYPE LINE
	STATUS OFF
	DATA watershd_dd
	PROJECTION #GEOGRAPHIC NAD83
		proj=longlat
		ellps=GRS80 
		no_defs 
	END
	TRANSPARENCY 70
	TEMPLATE "IDHUC8.htm"
	CLASS#
		NAME "Watersheds"
		COLOR 0 0 0 
	END
	METADATA
		"RESULT_FIELDS" "HUC"
		"wms_group_title" "BioSurvey"
		"wms_title" "Watersheds"
		legend_order "10"
	END
END

Here's the template - although it doesn't affect the results here - unless
it doesn't exist...

<html>
<body>
<table align=center valign=top width=95% border=0 celpadding=0 cellspacing=0
class=key_background>
	<tr ><td align=center class=key_header colspan=2>Identify
Results</td></tr>
	<tr><td align=center colspan=2><b>HUC:</b> [HUC]<br></td></tr>
	<tr><td>Region: [REGION]</td><td>Subregion: [SUBREGION]</td></tr>
	<tr><td>Acctunit: [ACCTUNIT]</td><td>Hydrounit:
[HYDROUNIT]</td></tr>
	<tr><td>Proper Name: [PROPER_NAM]</td><td>Main River:
[MAIN_RIVER]</td></tr>
	<tr><td colspan=2 align=center>Loc Desc: [LOCATION_D]</td></tr>
</table>
</body>
</html>

> -----Original Message-----
> From: Eric Bridger [mailto:eric at gomoos.org] 
> Sent: Friday, August 29, 2003 4:50 AM
> To: poff
> Cc: Mapserver List
> Subject: Re: [Mapserver-users] Unique? Was: mapscript - 
> queryByPoint help, simple Q
> 
> 
> Sorry you're having so much trouble. I do perl mapscript 
> queryByPoint extensively.  Have you tried looking att the 
> GMap PHP demo php source? It will show you how to do 
> everything with PHP mapscript.
> 
> http://www2.dmsolutions.ca/gmap/gmap75.phtml
> 
> E.g the following code is wrong:
> 
> > $my_point = ms_newpointObj(); 
> > $my_point->setXY($_REQUEST["mapa_x"],$_REQUEST["mapa_y"]
> 
> $_REQUEST["mapa_x"] and "mapa_y" are the pixel coordinates of 
> your mouse click. You need to first transform them to 
> geographic coordinates.  The gmap75.php file contains a 
> function: GMapPix2Geo() which does this.
> 
> Here's a perl example:
> sub get_click {
>     my ($q, $map) = @_;
>     my @current_extent = ();
>     my($x_map, $y_map) = (0,0);
> 
>     if($q->param('img.x') && $q->param('imgext')) { # Make 
> sure we got a click
>         @current_extent = split(' ', $q->param('imgext'));
>         my $click_x = $q->param('img.x');
>         my $click_y = $q->param('img.y');
>         my $x_pct = ($click_x / $map->{width});
>         my $y_pct = 1 - ($click_y / $map->{height});
> 
>         $x_map = $current_extent[0] + ( ($current_extent[2] -
> $current_extent[0]) * $x_pct);
>         $y_map = $current_extent[1] + ( ($current_extent[3] -
> $current_extent[1]) * $y_pct);
>     }
>     return ($x_map, $y_map);
> }
> 
> 
> 
> On Fri, 2003-08-29 at 12:08, poff wrote:
> > Hello
> > 
> > I know everyone is busy - and thanks a lot for your help.
> > 
> > Only, does _no-one_ use querbypoint with php mapscript?
> > 
> > It's a great feature if I could get it working, and definitely 
> > something to
> > go in Wiki someday!
> > 
> > Thanks
> > 
> > P
>  
> > 
> 
> 
> _______________________________________________
> Mapserver-users mailing list
> Mapserver-users at lists.gis.umn.edu 
> http://lists.gis.umn.edu/mailman/listinfo/maps> erver-users
> 
> 



More information about the mapserver-users mailing list