Querying a layer in Perl

Aaron Craig mercutio at POBOX.COM
Tue Jan 18 06:31:25 EST 2005


I had some code working that performed a query on a layer in a recent
pre 4.4 version of mapserver.

I've dusted it off and stuck it into a project I'm working on, and lo
and behold, it doesn't work!

I'm sure I'm missing something simple, but can't find it.

Any input is appreciated.

Here's a script that demonstrates the problem.  The coordinates of the
point I'm querying must work, as I've lifted them directly from my
Postgis database.  I open() the layer and set its status to ON, though
I'm not sure that is necessary.  I've also played with the buffer
parameter, but since I'm sending exactly the right point in, I don't
think that should make any difference.  I've also played with the type
parameter, but both MS_SINGLE and MS_MULTIPLE result in no results.


Here's the script:
=======================================================================
#!/usr/bin/perl

use warnings;
use strict;
use mapscript;

$| = 1;

my $map = new mapscript::mapObj("test.map");
my $lyr = $map->getLayerByName("museum");
$lyr->open();
$lyr->{status} = $mapscript::MS_ON;

my $pnt = mapscript::pointObj->new();
$pnt->{x} = 1536958.9653;
$pnt->{y} = 4439455.78984656;

my $rst = $lyr->queryByPoint($map, $pnt, $mapscript::MS_MULTIPLE, 0);
if($rst == $mapscript::MS_FAILURE)
        {
        my $err = mapscript::errorObj->new();

        if($err->{code} != 18)
                {
                print "Error running query on layer.";
                exit;
                }
        }

print "got ".$lyr->getNumResults()." results (expecting 1)\n";
====================================================================

The relevant layer declaration in the mapfile:
====================================================================

LAYER
   NAME "museum"
   TYPE POINT
   STATUS OFF

   CONNECTION 'user=postgres dbname=postgis_sardegna'
   CONNECTIONTYPE POSTGIS
   DATA 'point_geom from museum'

   CLASS
     NAME 'Museums'
     STYLE
       SYMBOL "/var/www/mapserver/htdocs/imgs/museum_icon.png"
     END
   END
END
====================================================================

And here's the result of a select query on my database:
select * from museum;
  id |   name   | xdb_id |                  point_geom
----+----------+--------+----------------------------------------------
   1 | museum 1 |        | SRID=-1;POINT(1536958.9653 4439455.78984656)
(1 row)


--
Aaron Craig
mercutio at pobox.com

===========================================================
Get Firefox!
http://www.spreadfirefox.com/?q=affiliates&id=0&t=1
===========================================================



More information about the mapserver-users mailing list