[Mapserver-users] Re: $shp->{resultscache} empty queryByPoint php mapscript - help!

Eric Bridger eric at gomoos.org
Fri Aug 29 10:13:36 PDT 2003


Well I won't say finally yet ... :-)

Now I'm confident that your problem is the EXTENT of your map and the
SIZE.  Your extents are way too large, the whole globe.  Pick some more
reasonable extents.  Then make sure your points are inside those
extents.  Then, make sure that your map SIZE exactly matches the aspect
ratio of your EXTENTS.
E.g. I use these extents for the Gulf of Maine:

EXTENT -71.5 39.5 -63.0 46.0
and this map size:
SIZE 504 385

e.g. (46 - 39.5) / (71.5 / 63) =  6.5/8 = 504/385

Getting the map size to match the extents is crucial when translating
your mouse click pixels to lat/lon.

Eric


On Fri, 2003-08-29 at 20:21, poff wrote:
> Hello all,
> 
> In a quest to get a php mapscript file to locate a click and return a 
> database value, you will have seen my many postings!
> 
> I can get a result, only it's "blank"...
> 
> Well I've made a super simplified setup and here it is:
> 
> php_mapscript 3.6.6
> windows nt/apache 1.3.8 - red hat linux
> 
> test.map
> NAME TEST_MAP
> 
> EXTENT -180 -90 180 90
> SIZE 370 331
> IMAGETYPE PNG
> 
> UNITS DD
> 
> WEB
> 
>   IMAGEPATH "/home/user/tmp/img/"
>   IMAGEURL  "/imgtmp/"
> 
> END
> 	
> LAYER
> 	NAME "QueryLayer"
> 	STATUS OFF
> 	TYPE POINT
> 	
> 	TEMPLATE "dummy"
> 	
> 	CLASS
> 		NAME "User Marker"
> 		SYMBOL "marker"
> 		COLOR 255 0 0
> 		SIZE 4
> 	END
> END
>   
> SYMBOL
> 	NAME 'marker'
> 	TYPE ELLIPSE
> 	POINTS 1 1 END
> 	FILLED TRUE
> END
> 
> END
> 
> the php file
> 
> <?php
> 
> dl("php_mapscript.so");
> 
> $map = ms_newMapObj("/home/user/maps/test.map");
> 
> $uLayer = $map->getLayerByName("QueryLayer");
> $uLayer->set("status",MS_ON);
> 
> /* zoom/pan stuff */
> 
> if ( isset($_REQUEST["mapa_x"])) {
> 
> 	$zoom=($_REQUEST["zoom"]=="select") ? 0 : $_REQUEST["zoom"];
> 	
> 	$extent_to_set = explode(" ",$_REQUEST["extent"]);
> 	
> 	$map->setextent($extent_to_set[0],$extent_to_set[1],
> 			$extent_to_set[2],$extent_to_set[3]);
> 
> 	$my_point = ms_newpointObj();
> 	$my_point->setXY($_REQUEST["mapa_x"],$_REQUEST["mapa_y"]);
> 
> 	$my_extent = ms_newrectObj();
> 	$my_extent->setextent($extent_to_set[0],$extent_to_set[1],
> 			$extent_to_set[2],$extent_to_set[3]);
> 
> 	$zoom_factor = $zoom*$_REQUEST["power"];
> 
> 	$val_zsize = abs($zoom_factor);
> 	
> 	if ($zoom_factor == 0)
> 		$zoom_factor=1;
> 
> 	
> 	$map->zoompoint($zoom_factor,$my_point,$map->width,$map->height,
> 			$my_extent);
> 
> 	$val_zsize = $_REQUEST["power"];
> }
> 
> $image=$map->draw();
> 
> /* sample lat/lon values */
> 
> $points=Array(
> "-0.1"=>"57",
> "33"=>"33",
> "66"=>"-55");
> 
> foreach ($points as $x => $y) {
> 
> 	$i++;
> 	
> 	$oPoint = ms_newPointObj();
> 	$oPoint->setXY($x, $y);
> 
> 	$oPoint->draw($map, $uLayer, $image, 0, "test");
> 	
> 	$line = ms_newLineObj();
>       	$line->add($oPoint);
>       	
>       	$shp=ms_newShapeObj(MS_SHAPE_POINT);
>       	$shp->add($line);
>       	$shp->{text}="test$i";
>       	$shp->{index}=$i;
>       	$uLayer->addFeature($shp);
> 
> }
> 
> /* if we are selecting a click */
> 
> if ( isset($_REQUEST["zoom"]) && $_REQUEST["zoom"]=="select") {
> 	
>         $dfKeyMapXMin = $map->extent->minx;
>         $dfKeyMapYMin = $map->extent->miny;
>         $dfKeyMapXMax = $map->extent->maxx;
>         $dfKeyMapYMax = $map->extent->maxy;
> 
>         $dfWidthPix = doubleval($image->width);
>         $dfHeightPix = doubleval($image->height);
>         
>         $nClickGeoX = GMapPix2Geo($_REQUEST['mapa_x'], 0, $dfWidthPix, 
> $dfKeyMapXMin, 
>                                    $dfKeyMapXMax, 0);
>         $nClickGeoY = GMapPix2Geo($_REQUEST["mapa_y"], 0, $dfHeightPix, 
> $dfKeyMapYMin, 
>                                   $dfKeyMapYMax, 1);	
>                                   
> 	$my_point = ms_newpointObj();
> 	$my_point->setXY($nClickGeoX,$nClickGeoY);
> 	
> 	$uLayer->queryByPoint($my_point, MS_SINGLE, 200);
> 	
> 	$results = $uLayer->{resultcache};
> 	
> 	$rslt = $uLayer->getResult(0);
> 	
> 	$database_id = $rslt->{shapeindex};
> 	
> 	echo $database_id;
> 
> 	// always -1
> 	
> 	exit;
> 
> }
> 
> $image_url=$image->saveWebImage(MS_PNG,1,1,0);
> 
> $extent_to_html = $map->extent->minx." ".$map->extent->miny." 
> ".$map->extent->maxx." ".$map->extent->maxy;
> 
> ?>
> 
> <form action="<?php echo $_SERVER["PHP_SELF"]?>" method="GET">
> 
> <input type=image name="mapa" width="<?=$map->width?>" 
> height="<?=$map->height?>" src="<?=$image_url?>">
> 
> <br>
> 
> <input name=zoom value="1" type="radio"> zoom in<br>
> <input name=zoom value="-1" type="radio"> zoom out<br>
> <input name=zoom value="0" type="radio"> pan<br>
> <input name=zoom value="select" type="radio"> select<br>
> 
> <input type="text" size="5" name=power class="theinput" VALUE="<?php echo 
> $val_zsize?>"> zoom power
> 
> <INPUT TYPE=HIDDEN NAME="extent" VALUE="<?php echo $extent_to_html?>">
> 
> </form>
> 
> <?php
> 
> /* from gmap */
> 
> function GMapPix2Geo($nPixPos, $dfPixMin, $dfPixMax, $dfGeoMin, $dfGeoMax, 
>                      $nInversePix) 
> {
>     
>     $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);
> }
> 
> ?>
> 
> If you could see anything I'm doing wrong I'd be MOST grateful!!
> 
> Thanks,
> 
> P
> -- 
> poff at sixbit.org
> SDF Public Access UNIX System - http://sdf.lonestar.org
> 
> Please do not carbon copy replies to me
> 





More information about the MapServer-users mailing list