[Mapserver-users] PHP/Mapscript -- Help doing queries

Vinko Vrsalovic vinko at cprsig.cl
Mon Mar 15 08:02:11 PST 2004


This snippet gives you an array ($result) with the shapes found for each
layer. 
>From here you should be able to add what you need, for instance, through
$lyr->data and $cmo->shapeindex...

@$map->queryByRect($pt);
for ($i=0;$i<$map->numlayers;$i++) {
	@$lyr = $map->getLayer($i);
	if ($lyr->type == MS_LAYER_POLYGON || $lyr->type == MS_LAYER_POINT || $lyr->type == MS_LAYER_LINE) {
		$lyr->open();
		for ($j=0;$j<$lyr->getNumResults();$j++) {
			$cmo = $lyr->getResult($j);
			$shp = $lyr->getShape($cmo->tileindex,$cmo->shapeindex);
			$result[$lyr->name][$j] = $shp;
		}
		$lyr->close();
	}
}




On Sun, Mar 14, 2004 at 09:49:16AM -0500, Ed Martin wrote:
> this is my first time doing queries with mapscript and i'm having some  
> problems, first i can't find any way that i can just put the shape  
> indexes of the results into an array along with the NAME value of the  
> dbf file, so since i can't do that i decided i would try to use a  
> template and then maybe i'll read the results from the template and put  
> into an array, but i can't get the template working, i get no errors at  
> all but it returns nothing, not even the static information in the  
> template, so i changed the template file to the php file i was working  
> on, and it worked but i can't use the php file as template, and the two  
> files have the same permissions and are in the same folder
> 
> so how can i get the templates working or preferably skip the template  
> and put the info i need into an array, please help
> 
> here is the template i'm trying to use
> 
> <tr>
> 	<td>
> 		<a href="index.phtml?shp=[shpidx]">[NAME]</a>
> 	</td>
> </tr>
> 
> here is the php that i'm using
> 
> 		dl("php_mapscript.so");
> 		$map = ms_newMapObj("map/map.map");
> 		//zoom/pan the
> 		$extent_to_set = explode(" ",$_SESSION['extent_old']);
> 		$map->setextent($extent_to_set[0],$extent_to_set[1],  
> $extent_to_set[2],$extent_to_set[3]);
> 		//calculate the coords
> 		$x_click =  
> ($_POST['mapa_x']/$map->width*($extent_to_set[2]- 
> $extent_to_set[0]))+$extent_to_set[0];
> 		$y_click =  
> ($_POST['mapa_y']/$map->height*($extent_to_set[3]- 
> $extent_to_set[1]))+$extent_to_set[1];
> 		$cities_layer = $map->getLayerByName('Cities');
> 		$point_obj = ms_newPointObj();
> 		$point_obj->setXY($x_click,$y_click);
> 		$query_tf = 
> 		@$cities_layer->queryByPoint($point_obj,MS_MULTIPLE,-1);
> 		if ($query_tf == MS_SUCCESS){
> 			echo 'Query worked<br />';
> 			echo $cities_layer->getNumResults().' places found';
> 			$query = $map->processquerytemplate('',FALSE);
> 			echo "<table>$query</table>";
> 		} else {
> 			echo 'Query Failed';
> 		}
> 		
>     and here is a bit of the map file
> 
> 	LAYER
> 		NAME "Cities"
> 		TYPE POINT
> 		STATUS default
> 		DATA  
> "/usr/local/apache/htdocs/adsbytown/site/mapserver/map/data/ci10de03"
> 		LABELMAXSCALE 1025400
> 		LABELITEM "NAME"
> 		MAXSCALE 4101800
> 		LABELCACHE on
> 		TOLERANCE 25
> 		TOLERANCEUNITS miles
> 		METADATA
> 			"title" "Title"
> 			"author" "Me!"
> 		END
> 		CLASS
> 			TEMPLATE 
> 			/usr/local/apache/htdocs/adsbytown/site/mapserver/query.tpl
> 			#php file i used was  
> /usr/local/apache/htdocs/adsbytown/site/mapserver/index.phtml
> 
> _______________________________________________
> Mapserver-users mailing list
> Mapserver-users at lists.gis.umn.edu
> http://lists.gis.umn.edu/mailman/listinfo/mapserver-users

-- 
Vinko Vrsalovic <el[|- at -|]vinko.cl>
http://www.cprsig.cl



More information about the MapServer-users mailing list