[Mapserver-users] Perl Mapscript queryByRect
Dane Haygood
dane_haygood at bellsouth.net
Fri Jul 30 14:17:03 PDT 2004
This is a multi-part message in MIME format.
------=_NextPart_000_0045_01C47650.A6904330
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
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 =3D new mapscript::mapObj($map_path.$map_file);
$rectangle =3D $map->{extent};
my $parcelLayer =3D $map->getLayerByName('hydro_query');
my $status =3D $parcelLayer->queryByRect($map, $rectangle);
if ($status =3D=3D MS_FAILURE) {
print("no items found for query\n");
exit;
}
my $numResults =3D $parcelLayer->getNumResults();
print("query returned $numResults results\n");
my $result =3D $parcelLayer->getResult(0);
print("RESULTS: $result\n");
#########################################################################=
###########
# MAP FILE
#########################################################################=
###########
#--------------------------------------
# LAYER: Parcel Data
#--------------------------------------
LAYER=20
NAME hydro_query
DATA hydro.shp
STATUS ON
TYPE QUERY
TEMPLATE 'none'
CLASS
COLOR 243 241 203
OUTLINECOLOR 128 128 128
END
END
------=_NextPart_000_0045_01C47650.A6904330
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1400" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2></FONT><BR><FONT face=3DArial =
size=3D2>I am attempting=20
to use the queryByRect function of mapscript - but it seems I am doing =
something=20
wrong.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I read somewhere that the query only =
occurs on=20
Layers where TEMPLATE is defined in the mapfile.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>If I include a TEMPLATE definition in =
the layer I=20
want to query - I get <FONT face=3D"Courier New">"no items found for =
query"<FONT=20
face=3DArial></FONT></FONT></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>which indicates that my call to =
queryByRect=20
returned MS_FAILURE.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>I have tried playing with the STATUS, =
TEMPLATE, and=20
TYPE definitions in the layer of the mapfile.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I get the same results regardless if =
the file=20
specified by the value for TEMPLATE actually exists or not.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>I have included snippets from both the =
perl script=20
and from the mapfile below.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I have manually set the rectangle =
extents but=20
figured this code should return all the items in the layer.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Thanks for any help...</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial>
<DIV><FONT face=3D"Courier New"=20
size=3D2>################################################################=
####################</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2># PERL SCRIPT</FONT></DIV>
<DIV>
<DIV><FONT face=3D"Courier New"=20
size=3D2>################################################################=
####################</FONT></DIV></DIV></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2>$map =3D new=20
mapscript::mapObj($map_path.$map_file);<BR>$rectangle =3D=20
$map->{extent};</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2>my $parcelLayer =3D=20
$map->getLayerByName('hydro_query');<BR></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2>my $status =3D=20
$parcelLayer->queryByRect($map, $rectangle);<BR>if ($status =3D=3D =
MS_FAILURE)=20
{<BR> print("no items found =
for=20
query\n");<BR> =
exit;<BR>}</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2>my $numResults =3D=20
$parcelLayer->getNumResults();<BR>print("query returned $numResults=20
results\n");</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2>my $result =3D=20
$parcelLayer->getResult(0);<BR>print("RESULTS: =
$result\n");</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New"=20
size=3D2>################################################################=
####################</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2># MAP FILE</FONT></DIV>
<DIV>
<DIV><FONT face=3D"Courier New"=20
size=3D2>################################################################=
####################</FONT></DIV></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" =
size=3D2> =20
#--------------------------------------<BR> =
=20
# LAYER: Parcel Data<BR> =20
#--------------------------------------<BR> =
=20
LAYER=20
<BR> &nb=
sp; =20
NAME=20
hydro_query<BR> &nbs=
p; =20
DATA=20
hydro.shp<BR> =
=20
STATUS=20
ON<BR> &=
nbsp; =20
TYPE=20
QUERY<BR> &nbs=
p; =20
TEMPLATE=20
'none'<BR> &nb=
sp; =20
CLASS<BR> &nbs=
p;  =
;=20
COLOR 243 241=20
203<BR> =
=
OUTLINECOLOR 128 128=20
128<BR> =
=20
END<BR> END<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV></BODY></HTML>
------=_NextPart_000_0045_01C47650.A6904330--
More information about the MapServer-users
mailing list