MapScript queryByPoint index error
Jerod Clabaugh
jclabaugh at MAC.COM
Fri Mar 11 10:07:12 PST 2005
All:
I am in the process of using PHP/MapScript to build a dynamic point
layer that I can query.
When I query the point layer, the result (using an echo) shows me
$result ->shapeindex=-1
The code to query the layer and to build this layer are detailed
below. I have built a rectangular query, which works with the same
dynamic layer, but I am having trouble with the point layer.
Any advice on why I am getting the wrong indexes in the results of
queryByPoint on the dynamic layer?
Thanks in advance,
Jerod Clabaugh
TransNatura, LLC
#####
# Code to query layer and display results
#####
=-=-=-=-=-=-=
if( MS_SUCCESS != @$layer->queryByPoint( $my_point,
MS_MULTIPLE, -1 ) ){ continue; }
$lname = $layer->name;
$result_count = $layer->getNumResults();
if( $result_count ){
$layer->open();
for( $i = 0; $i < $result_count; $i++ ){
$result = $layer->getResult( $i );
if( $result && $result->shapeindex > -1 ){
$shape = $layer->getShape(
-1, $result->shapeindex );
echo "shpInd:". $result->shapeindex ."<BR/>";
if( count( $shape->values ) ){
$query_results[
$lname ][ $i ] = $shape->values;
}
}
}
$layer->close();
}
######
#####
#Code to build the dynamic layer:
#####
foreach( $points as $row ){
$pt = $row["point"];
$g = $row["genus"];
$classname = $g ." ". $row["species"]
.( $row["subspecies"] ? " ". $row["subspecies"] : "" )
.( $row["var"] ? " var. ". $row["var"] : "" );
if( !in_array( $classname, $legended_species ) ){
array_push( $legended_species, $classname );
$dummy_class = $species_layer_dummy_classes[
$species_layer_dummy_class_index ];
$classObj = ms_newClassObj( $layer, $dummy_class );
$classObj->set( "status", MS_ON );
$classObj->set( "name", $classname );
++$species_layer_dummy_class_index;
}
$line = ms_newLineObj();
$line->add( $pt );
$shp = ms_newShapeObj( MS_SHAPE_POINT );
$shp->add( $line );
$shp->index = $point_number;
//$shp->set("tileindex", $point_number );
//$shp->index = $point_number;
$classname2index = array_flip( $legended_species );
$shp->set( "classindex", $classname2index[ $classname ] );
/*$rect = ms_newRectObj();
$rect->minx = $pt.x - 150;
$rect->miny = $pt.y - 150;
$rect->maxx = $pt.x + 150;
$rect->maxy = $pt.y + 150;
$shp->rectObj = $rect;*/
$layer->addFeature( $shp );
//draw(mapObj map, layerObj layer, imageObj img, int
class_index, string text)
//$pt->draw( $map, $layer, $img, $genus2index[ $g ], "TEST" );
$pt->draw( $map, $layer, $img, $classname2index[
$classname ], "TEST" );
//$pt->draw( $map, $layer, $img, $point_number, "TEST" );
++$point_number;
}
######
More information about the MapServer-users
mailing list