[Mapserver-users] Perl Mapscript queryByRect

Eric Bridger eric at gomoos.org
Sat Jul 31 00:04:59 EDT 2004


At 04:17 PM 07/30/2004 -0500, Dane Haygood wrote:

>I am attempting to use the queryByRect function of mapscript - but it seems I am doing something wrong.
>I read somewhere that the query only occurs on Layers where TEMPLATE is defined in the mapfile.
>If I include a TEMPLATE definition in the layer I want to query - I get "no items found for query"
>which indicates that my call to queryByRect returned MS_FAILURE.
> 
>I have tried playing with the STATUS, TEMPLATE, and TYPE definitions in the layer of the mapfile.
>I get the same results regardless if the file specified by the value for TEMPLATE actually exists or not.
> 
> 
> 
>I have included snippets from both the perl script and from the mapfile below.
>I have manually set the rectangle extents but figured this code should return all the items in the layer.
> 
>Thanks for any help...
> 
>####################################################################################
># PERL SCRIPT
>####################################################################################
> 
>$map =  new mapscript::mapObj($map_path.$map_file);
>$rectangle = $map->{extent};
> 
>my $parcelLayer = $map->getLayerByName('hydro_query');
>my $status = $parcelLayer->queryByRect($map, $rectangle);
>if ($status == MS_FAILURE) {
>        print("no items found for query\n");
>        exit;
>}
> 
>my $numResults = $parcelLayer->getNumResults();
>print("query returned $numResults results\n");
> 
>my $result = $parcelLayer->getResult(0);
>print("RESULTS: $result\n");

Have you tried turning the layer on explicitly before the query.

$parcelLayer->{status} = $mapscript::MS_ON;

If that doesn't work try a LAYER TYPE of POLYGON vs. QUERY.

Also you could try queryByPoint() with a large tolerance to accomplish a rect query.

HTH.
Eric





More information about the mapserver-users mailing list