[mapserver-users] MapScript querybypoint using mapObj rather than layerObj
Joe Nunn
joe.nunn at usegis.co.uk
Wed Jul 29 07:57:46 PDT 2009
Hi
I am using MapScript to perform a querybypoint and I have succeeded in
querying each individual layer however this is slow and I wonder if this is
possible (as the documentation suggests) by querying the mapObj and come
back results from all layers within the mapfile.
My current code is:
$o_map = ms_newMapObj("QueryCounties.map");
$v_nl = $o_map->numlayers;
$o_point = ms_newPointObj();
$o_point->setXY($v_longitude, $v_latitude);
//loop through layers in mapfile
for($j = 0; $j < $v_nl; $j++) {
$o_query_layer = $o_map->getLayer($j);
$o_query_layer->set("status",1);
//select layer if point lies within layer
if ((@$o_query_layer->queryByPoint($o_point, MS_MULTIPLE,
-1))==MS_SUCCESS) {
$o_query_layer->open();
//gets the first result from each query
$o_result = $o_query_layer->getResult(0);
$o_shape =
$o_query_layer->getShape(-1,$o_result->shapeindex);
//return values from columns of shapefile
$v_decade = $o_shape->values["NAME"];
And my attempt to perform queryByPoint on a mapObj is like this:
$o_query = $o_map->queryByPoint($o_point, MS_MULTIPLE, -1);
echo "query_results: ".$o_query;
My Mapfile looks like this:
MAP
NAME "Counties"
SHAPEPATH "C:\Data\
STATUS ON
PROJECTION
"init=epsg:4326"
END
LAYER
NAME Counties1790
STATUS ON
DATA "US_county_1790_region.shp"
TYPE POLYGON
CLASS
NAME "counties"
TEMPLATE "void"
END
END
LAYER
NAME Counties1810
STATUS ON
DATA "US_county_1810_region.shp"
TYPE POLYGON
CLASS
NAME "counties"
TEMPLATE "void"
END
END
.....
END
Anyone know how to get this querybypoint working on a mapobj and if it will
speed up the code?
All the best
Joe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20090729/dce1248a/attachment.htm>
More information about the MapServer-users
mailing list