queryByAttributes - speed

Jeppe Lund Andersen JXA at COWI.DK
Tue Feb 27 06:06:56 EST 2007


Hello all

Iam running php mapscript on a windows 2003 server and when Iam using
queryByAttributes, but it take some time to perform the search.
It takes between 7-8 sek for this linie

$Qry = @$Layer->queryByAttributes($ID_navn, '(' . $Search_Str .')',
$ResultType);

The file iam using is a mapinfo file which has cadastral information.
there are 156612 records in the file and the coln iam searching in has
been index via mapifno.
the field is a text field

Am I doing something wrong ?

Jeppe

here is the funktion that load the map and perform the search

function FindExtendForMatrikel()
{
	global $GISREF_LAYER_NAME, $MAP_PATH_NAME, $MAP_FILE_NAME,
$MATRIKEL_ID_NAME;;
	global $xmin, $ymin, $xmax, $ymax;
	global $MATRIKEL_LAYER_NAME, $starttid, $kort;
	$Shape_matr = array();
	
	$Result = mssql_query ("select * from kort WHERE name = '".
$MATRIKEL_LAYER_NAME . "'");
	while ($row = mssql_fetch_array($Result)) 
	{
		$Map = ms_newMapObj($MAP_FILE_NAME);
		$Layer = ms_newLayerObj($Map);
		$Layer->set('name', "MatrikelSearchLayer");
		$Layer->set("connection", $row['MS_CONNECTION']);
		$Layer->set("connectiontype", MS_OGR);
		$Layer->set('status', MS_OFF);
		$Layer->set('type', MS_LAYER_POLYGON);
		$Layer->setProjection($row['MS_PROJECTION']);
		$Class = ms_newClassObj($Layer);
		$Class->set('name', "Matrikler");
		$Class->set('template', 'void');
	}
	
	foreach ($kort->objekter as $value) 
	{
		if ($value->ObjType() == "Matrikel") 
		{
	    
			$ID_value = $value->id;
			$Layer =
$Map->getLayerByName("MatrikelSearchLayer");
			//$ID_value = "78065110g";
			$ID_navn = $MATRIKEL_ID_NAME;
			$ResultType = MS_MULTIPLE;
			
			$Search_Str = "";
			$matr_array = split(',', $ID_value);
			  
			foreach ($matr_array as $matr) 
			{
			  	if ($Search_Str != "") {
					$Search_Str .= " OR ";
				}
				$Search_Str .= " '[$ID_navn]' = '$matr'
";
			}
			
			$Qry = @$Layer->queryByAttributes($ID_navn, '('
. $Search_Str .')', $ResultType);
			$QryRes = $Layer->getNumResults();
			if ($QryRes == 0 ) { $kort->matrikelsogning =
NULL;}
			
			for ($I = 0; $I < $QryRes; $I++) 
			{
			  	$Res = $Layer->getResult($I);
			 	$Layer->open();
			    	$Shape_matr[] =
$Layer->getShape($Res->tileindex, $Res->shapeindex);
				$Layer->close();
				
			}
		}
	}
	
}



More information about the mapserver-users mailing list