mapscript query question

Peter deVoil devoilp at dpi.qld.gov.au
Thu May 18 18:56:33 EDT 2000


Hi,

I was working on some TCL code for queries yesterday. 

Paul Cameron wrote:
> 
> Hello,
> 
> I've been trying to figure out how the queries work with mapscript and
> was hoping someone could shed some light on it. I'd like to do a simple
> point in polygon query and get access to the dbf record for that polygon.
> The script is crashing on the line that calls queryByPoint with an
> internal server error. If anyone has some code that deals with queries in

Core dump? or no queries returned?

> mapscript and are willing to share I'd be very appreciative.
> 
> Thanks,
> paul
> 
> Here's the code that's relevant to the query:
> 
> #!/usr/local/bin/perl
> 
> use mapscript;
> use CGI qw(:standard :html escape);
> 
> $cgi = new CGI;
> $query_type = $mapscript::MS_SINGLE;
> 
> $mode = $cgi->param('mode');
> $x = $cgi->param('img.x');
> $y = $cgi->param('img.y');
> 
> $mapfile = '/usr/people/pcameron/survey/scott/web/mapscript.map';
> 
> $map = new mapObj("$mapfile") or die "Unable to load map file. ",
> $mapscript::ms_error->{message};
> 
> if ($mode eq 'query') {
>   $query_buffer = 10;

I'm guessing that this is your problem - setting the buffer size to -1
should 
use each layer's tolerance.

>   $query = new queryResultObj;
>   $point = new pointObj();
>   $point->{x} = $x;
>   $point->{y} = $y;
>   $query = $map->queryByPoint($point,$query_type,$query_buffer);
>   &process_query;
> }

Then you have to do something with the query itself. Here's what I do in
TCL 
(this exposes shortcomings of SWIG/tcl - it's close to unreadable.)

------
   set p [canvas2point $c $config(map) $x $y]

   if {[set q [mapObj_queryUsingPoint $config(map) $p 1 -1]] != "NULL"}
{
       queryResultObj_currentlayer_set $q 0
       queryResultObj_currentshape_set $q 0
       for {set s [queryResultObj_next $q]} \
            {[shapeResultObj_layer_get $s] >= 0 &&
	    [shapeResultObj_shape_get $s] >= 0} \
	   {set s [queryResultObj_next $q]} {
             $txt insert end " $s, layer [shapeResultObj_layer_get $s],
shape [shapeResultObj_shape_get $s]\n"
             set dbf $config(dbfFile)
	     if {![file exists $dbf]} {error "missing dbf $dbf!"}
               set h [DBFOpen $dbf rb]
	       set w [DBFGetFieldCount $h]
	       for {set i 0} {$i < $w} {incr i} {
                  set name [DBFGetFieldName $h $i]
		  set value [DBFReadStringAttribute $h [shapeResultObj_shape_get $s]
$i]
		  $txt insert end "$name $value\n"
               }
	       DBFClose $h
.....
----------



More information about the mapserver-users mailing list