[Mapserver-users] question re Perl queryByShape

Puneet Kishor pkishor at geoanalytics.com
Mon Sep 22 12:33:44 EDT 2003


strangeness continues --


I am doing something very basic -- creating a shape, and then using it 
to query another layer. If I do queryByShape, I get way more features 
selected than should be. If I create a rect using the bounds of the 
shape, I get the correct number of features. In other words --

my $queryLayerObj = $mapObj->getLayerByName("somelayer");
my $queryShpObj = new blah blah;
$queryShpObj->setBounds;
	my $tminx = $queryShpObj->{bounds}->{minx}; my $tminy = 
$queryShpObj->{bounds}->{miny};
	my $tmaxx = $queryShpObj->{bounds}->{maxx}; my $tmaxy = 
$queryShpObj->{bounds}->{maxy};
$queryLayerObj->queryByShape($mapObj, $queryShpObj);
my $resultCacheObj = $queryLayerObj->{resultcache};
my $numofresults = $resultCacheObj->{numresults};
print "$numofresults features found within the following coords\n";
print "$tminx, $tminy, $tmaxx, $tmaxy\n";

% 155 features found within the following coords
% 578816.299144084 1984697.32335303 579216.298984191 1985097.3229533

my $queryLayerObj = $mapObj->getLayerByName("somelayer");
my $queryShpObj = new blah blah;
$queryShpObj->setBounds;
	my $tminx = $queryShpObj->{bounds}->{minx}; my $tminy = 
$queryShpObj->{bounds}->{miny};
	my $tmaxx = $queryShpObj->{bounds}->{maxx}; my $tmaxy = 
$queryShpObj->{bounds}->{maxy};
my $queryRectShpObj = new 
mapscript::shapeObj($mapscript::MS_SHAPE_POLYGON);
	my $rectline = new mapscript::lineObj; my $rectpoint = new 
mapscript::pointObj;
	$rectpoint->{x} = $tminx; $rectpoint->{y} = $tminy; 
$rectline->add($rectpoint);
	$rectpoint->{x} = $tminx; $rectpoint->{y} = $tmaxy; 
$rectline->add($rectpoint);
	$rectpoint->{x} = $tmaxx; $rectpoint->{y} = $tmaxy; 
$rectline->add($rectpoint);
	$rectpoint->{x} = $tmaxx; $rectpoint->{y} = $tminy; 
$rectline->add($rectpoint);
	$rectpoint->{x} = $tminx; $rectpoint->{y} = $tminy; 
$rectline->add($rectpoint);
$queryRectShpObj->add($rectline);
$queryRectShpObj->setBounds;
my $queryRectObj = $queryRectShpObj->{bounds};
	my $rminx = $queryRectObj->{minx}; my $rminy = $queryRectObj->{miny};
	my $rmaxx = $queryRectObj->{maxx}; my $rmaxy = $queryRectObj->{maxy};
$queryLayerObj->queryByRect($mapObj, $queryRectObj);
my $resultCacheObj = $queryLayerObj->{resultcache};
my $numofresults = $resultCacheObj->{numresults};
print "$numofresults features found within the following coords\n";
print "$rminx, $rminy, $rmaxx, $rmaxy\n";

% 13 features found within the following coords
% 578816.299144084 1984697.32335303 579216.298984191 1985097.3229533


what gives? Am I doing something wrong here? Is this a bug? The coords 
in boths cases are identical... but queryByShape seems to be throwing a 
wider (and wrongly so) net.


On Monday, September 22, 2003, at 06:03  AM, Eric Bridger wrote:

> The functionality you want already exists.
>
> Both the map and layer objects have queryByShape() methods.  So
> $mapObj->queryByShape() will query all layers which are ON.
> $layerObj->queryByShape() queries only that layer.
>
>
>
> On Mon, 2003-09-22 at 13:59, Puneet Kishor wrote:
>> as I understand, here's the logic for querying by shape --
>>
>> 1. create a shape to query with (queryShpObj)
>>
>> 	my $queryShpObj = new blah blah;
>>
>> 2. call queryByShape on the map object (mapObj) using the above shape
>>
>> 	$mapObj->queryByShape($queryShpObj);
>>
>> Now, herein lies my question -- how does mapobject know which layer to
>> query against? The intuitive model that I have learned (the Pavlovian
>> Arcview way) is that you have first choose a layer before you can 
>> query
>> against it. Even if we extend that model, we can make it plural...
>> choose the layer or layers against which to query. So the syntax 
>> should
>> be somewhat like
>> 	my $queryLayerObj = new blah blah (proabably with a getLayerByName);
>> 	$mapObj->queryByShape($queryShpObj, $queryLayerObj);
>>
>> Once that is done then one could(should) work with the $resultCacheObj
>>
>> 	my $resultCacheObj = $queryLayerObj->{resultcache};
>>
>> Not specifying the queryLayer(s) in step 2 above -- doesn't that make
>> things slower?
>>
>> _______________________________________________
>> Mapserver-users mailing list
>> Mapserver-users at lists.gis.umn.edu
>> http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
>>
>
>




More information about the mapserver-users mailing list