[Mapserver-users] searching in layer (newbie)

Martin Kiuru Martin.Kiuru at Elion.ee
Thu Feb 19 09:45:11 EST 2004


Hi Lowell,

Thanks for your answer !

Here is my code. If you know some better way to search single polygons
in layer, please tell me... Also, if you have some idea how to display
this polygon in different color - it will be great to hear about it :)

Best Regards,
Martin

if ( $http_form_vars["parcel-number"] )
{
		// the parcel number to query for
	$szParcelNumber = $http_form_vars["parcel-number"];
		// the current extents will be the default if we fail.
            //$oMapSession->oMap->setExtent( MAX_EXT_MINX, MAX_EXT_MAXX,
MAX_EXT_MINY, MAX_EXT_MAXY );
	$oExtents = $oMapSession->oMap->extent;
	$oldExtents = $oExtents; 
		//first we need a handle on the layer, let's assume that
we have
		//it's name
	$oParcelLayer = $oMapSession->oMap->getLayerByName( "TUNNUSED"
);
		// set up the layer for a query in ms 3.6 - in 3.7 we
don't need
		// to do this, we can just use querybyattribute. Here we
assume
		// that the data file associated with the layer has an
attribute
		// called parcel_number that we are querying.
	$oParcelLayer->set( "filteritem", "TUNNUS" );
	$oParcelLayer->setFilter( "\"$szParcelNumber\"" );
		// use querybyattribute to generate the result, assume a
single
		// one for simplicity but this can be extended to
multiple
		// results easily
	
$oParcelLayer->queryByAttributes('TUNNUS','/'.$szParcelNumber.'/',MS_SIN
GLE);
		//now check to see if there are any results?
	If ($oParcelLayer->getNumResults() > 0 )
	{	

			//at least one result, assume only one for this
example
		$oResult = $oParcelLayer->getResult( 0 );
			//oResult is a resultCacheMemberObj
		$oParcelLayer->open(); //new code
		$oShape = $oParcelLayer->getShape(
$oResult->tileindex,$oResult->shapeindex );
		$oExtents = $oShape->bounds;
		$oShape->free();
		$oParcelLayer->close();
	}
	$sessWidth=$oMapSession->oMap->width;
	$sessHeight=$oMapSession->oMap->height;
	
$px1=$sessWidth/($oldExtents->maxx-$oldExtents->minx)*($oExtents->minx-$
oldExtents->minx);
	
$px2=$sessWidth/($oldExtents->maxx-$oldExtents->minx)*($oExtents->maxx-$
oldExtents->minx);
	
$py1=$sessHeight/($oldExtents->maxy-$oldExtents->miny)*($oldExtents->max
y-$oExtents->maxy);
	
$py2=$sessHeight/($oldExtents->maxy-$oldExtents->miny)*($oldExtents->max
y-$oExtents->miny);
	$pxX=($px1 + $px2)/2 ;
	$pyY=($py1 + $py2)/2 ;

	if ($oExtents != $oldExtents ) 
	{
		$oMapNavigator->zoomScale(8000, $pxX, $pyY);
	}
}


-----Original Message-----
From: Lowell Filak [mailto:lfilak at medinaco.org] 
Sent: Thursday, February 19, 2004 4:31 PM
To: Martin Kiuru; mapserver-users at lists.gis.umn.edu
Subject: Re: [Mapserver-users] searching in layer (newbie)


I think you may need to include more information/code, if I'm not
mistaken getlayerbyname should return a layer handle without a
reselection. It sounds like the handle your using may be the
resultcaheobj instead of the new layerobj.? But then I could be
completely off base...

Lowell

The following message was sent by "Martin Kiuru" <Martin.Kiuru at Elion.ee>
on Thu, 19 Feb 2004 15:31:18 +0200.

> Hi.
>  
> I have a problem with a search using queryByAttributes() in 
> tileindexed layer. After first search, when searched object is zoomed,

> all next searches will work only with a displayed zoomed area - it 
> seems that after zooming getLayerByName() returns only zoomed area of 
> the layer. So, my question is how to reset layer to initial state, to 
> search in whole layer ?
>  
> Thanks in advice,
> Martin.
> 





More information about the mapserver-users mailing list