querying attributes in mapserver

Stephen Lime steve.lime at dnr.state.mn.us
Mon Oct 9 08:09:29 PDT 2000


You must create a query object for all layers you intend to query. I realize you
generally won't actually use that object much, if at all, in mapscript, but the 
query routines rely on it's presence to determine wether or not a layer is queryable.
This will likely change at somepoint but for now just add:

QUERY
  TEMPLATE dummy
END

to your layer def and then retry it.

Steve

Stephen Lime
Internet Applications Analyst

Minnesota DNR
500 Lafayette Road
St. Paul, MN 55155
651-297-2937

>>> Michael Kleih <michael.kleih at jrc.it> 10/05/00 03:34AM >>>
Hello,

I made a lot of attempts in querying the attributes of a shapefile
using mapscript, but always failed. For example in the
following example I tried to print out the number of results
I should get with my query. The mapfile 'countries_onec.map'
that I use has the following content:

NAME DEMO
STATUS ON
SIZE 600 600
EXTENT -5 34.66 20 60.83
UNITS DD
SHAPEPATH "data"
IMAGECOLOR 80 204 255
TRANSPARENT OFF

   LAYER
     NAME country
     TYPE POLYGON
     STATUS ON
     DATA country
     TOLERANCE 3
     CLASSITEM Color_map
     CLASS
       EXPRESSION ([COLOR_MAP]<9)
       COLOR 0 174 66
       BACKGROUNDCOLOR 0 204 255
       OUTLINECOLOR 0 0 0
     END

   END
END

The mapscript script in PERL has the following content:

#!/usr/bin/perl

use mapscript;
use GD;

$map = new mapObj('countries_onec.map') or die('Unable to open
mapfile.');
$img = $map->draw() or die('Unable to draw map');
mapscript::msSaveImage($img, "out.gif", false, false);

$lay = $map->getLayer(0);
$rect = new rectObj();
$rect ->{minx}=197;
$rect ->{miny}=297;
$rect ->{maxx}=203;
$rect ->{maxy}=303;
$qeur= $lay->queryUsingRect($map,$rect);
print $qeur->numresults;

This should print me the number of results of the query, but instead
I get the message:

Can't call method "numresults" on an undefined value at ./scripttst.pl

Can somebody help? It would really be nice!

Michael



--
__________________________________

Michael Kleih
Centro Comune di Ricerca-JRC
Commissione Europea
Via Fermi 1
TP 270
Tel. 0039/0332785039

__________________________________






More information about the MapServer-users mailing list