[mapserver-dev] Querying line with queryByRect() only works on the line ending point

Hawk_AA hawk at aamdal.com
Mon Oct 5 04:15:45 EDT 2009


Hi there,

I'm developing an application that allows the user to click on certain map
features, like a point or line, to get info about it (stored in a Microsoft
SQL database, connected with an ID column) . I am now able to click on a
point to get info about it, but to get info about a line, i need to click on
the end of the line. If i try to click on the middle of it, the queryByRect
wont give me the ID of the line. Here is the layer definition:

LAYER
	NAME Traseer
	GROUP TelMe
	TYPE LINE
	STATUS ON
	CONNECTIONTYPE OGR
	CONNECTION "TM_Nett/TM_Traces.TAB"
	STYLEITEM "AUTO"
	minscaledenom 0
	maxscaledenom 300000
	CLASSITEM "Type"
	DUMP TRUE
	CLASS
		NAME "Traseer"
		TEMPLATE "ttt_query.html"
        	SYMBOL "default-circle"
        	COLOR 255 0 255
	END
END # Layer

When i click a point in fusion, it creates a rectangle (10x10 pixles) around
the click position, and converts it to geographic coordinates. Then it sends
all to this mapscript:

<?php
/*****************************************************************************
 * Purpose: create a query by attributes

*****************************************************************************/

  /* set up the session */
include ("Common.php");
include ("Utilities.php");
include('../../common/php/Utilities.php');


$strPointLayer = $_REQUEST['pointLayer'];
$strTraceLayer = $_REQUEST['traceLayer'];
$arrTraceIDs = array();
$arrPointIDs = array();


$result = "";


if (!isset($mapName)) {
     die('Mapname not set');
}
if (isset($_SESSION['maps']) && isset($_SESSION['maps'][$mapName])) {
     $oMap = ms_newMapObj($_SESSION['maps'][$mapName]);
}

$rectObj = ms_newRectObj();
$rectObj->set("minx",$_REQUEST['sMinX']);
$rectObj->set("miny",$_REQUEST['sMinY']);
$rectObj->set("maxx",$_REQUEST['sMaxX']);
$rectObj->set("maxy",$_REQUEST['sMaxY']);

$oPointLayer = $oMap->GetLayerByName($strPointLayer);

if (@$oPointLayer->queryByRect($rectObj, MS_MULTIPLE)== MS_SUCCESS)
{
	 $numResults = $oPointLayer->getNumResults();
	 
	 
	 $oPointLayer->open(); 
	 
     $arrPointIDs = array();
	 for ($iResult = 0; $iResult<$numResults; $iResult++) {
	 	$oResultSet = $oPointLayer->getResult($iResult);
		$oShape =
$oPointLayer->getShape($oResultSet->tileindex,$oResultSet->shapeindex);
		array_push($arrPointIDs, $oShape->values['Point_ID']);
	 }	 
     $oPointLayer->close();
}

$oTraceLayer = $oMap->GetLayerByName($strTraceLayer);

if (@$oTraceLayer->queryByRect($rectObj)== MS_SUCCESS)
{
	 $numResults = $oPointLayer->getNumResults();
     $result = $numResults;
	 
	 
	 $oTraceLayer->open(); 
	 
	 for ($iResult = 0; $iResult<$numResults; $iResult++) {
	 	$oResultSet = $oTraceLayer->getResult($iResult);
		$oShape =
$oTraceLayer->getShape($oResultSet->tileindex,$oResultSet->shapeindex);
		array_push($arrTraceIDs, $oShape->values['Trace_ID']);
	 }
	 
	
	 
	 
     $oTraceLayer->close();
}

$result = "Point_ID=" . implode(",", $arrPointIDs) . "&Trace_ID=" .
implode(",", $arrTraceIDs);

echo var2json($result);

?>

This script works all fine if the ending(or starting) points are within the
rectangle . But are there any way to query for the whole line geometry?
Would it make any difference if I queried by CGI?

I hope any of you can help me out.
Sincerely,
Håkon
-- 
View this message in context: http://n2.nabble.com/Querying-line-with-queryByRect-only-works-on-the-line-ending-point-tp3767516p3767516.html
Sent from the Mapserver - Dev mailing list archive at Nabble.com.


More information about the mapserver-dev mailing list