[Chameleon] QueryByShape

Normand Savard nsavard at mapgears.com
Tue Oct 16 13:46:36 EDT 2007


Mariette wrote:

>Greetings,
>
>Would someone have an example on setting up QUeryByShape. I am attemting to
>use it but cannot get the result to popup in a window, the page simple
>reloads blank.
>
>  
>
Mariette,

This is an example where a point is used to select a shape on park layer 
(chameleon map).  This shape is then used to do a queryByShape selection 
on drainage layer.

Norm

<?php
include_once('/home/nsavard/programs/src/dev/php/log.php');
dl('php_mapscript.so');
$map = ms_newMapObj("/ms4w/apps/chameleon/samples/map/chameleon.map");

$srclayer = $map->getLayerByName('park');
$targetlayer = $map->getLayerByName('drainage');

$georef_x =-978456;
$georef_y = 1280409;
 
$my_point = ms_newpointObj();
$my_point->setXY($georef_x,$georef_y);

//This point is used for the shape selection that will be used to select 
other shapes
if ($srclayer->queryByPoint ($my_point,MS_SINGLE,-8) == MS_SUCCESS) {
        echo("Request queryByPoint, coords : (".$georef_x.", 
".$georef_y.").</br>\n");
        $result = $srclayer->getResult(0);
        $srclayer->open();
        $indexShape = $result->shapeindex;

        $shape = $srclayer->getShape(-1, $indexShape);
        echo("Park selected : ".$shape->values["NAME_E"]."</br></br>\n");
        //Park selected shape is used to select drainage shapes
        if ($targetlayer->queryByShape($shape) == MS_SUCCESS) {
                echo("Requeste queryByShape using the selected shape 
.</br>");
                printf("Results : ".$targetlayer->getNumResults()." 
polygons.</br>\n");
                $targetlayer->open();
                for ($j=0; $j<$targetlayer->getNumResults(); $j++) {
                        $result = $targetlayer->getResult($j);
                        $indexShape = $result->shapeindex;
                        $shape = $targetlayer->getShape(-1, $indexShape);
                        $nom = $shape->values["NAME"];
                        echo($j.", shapeindex : ".$indexShape.", Name : 
".$nom."</br>");
                }
       } else {
                echo("Error last request.</br>\n");
       }
} else {
        print "Error first request.</br>\n";
}




More information about the Chameleon mailing list