QueryByRect problem in PHPmapscript

Bill Thoen bthoen at GISNET.COM
Wed Oct 31 17:24:04 EDT 2007


I simplified it to one layer in the map, so I'm sure I'm getting the 
states layer (originally I had two states layers -- polygon and line -- 
so that's why I used the number). And now that I'm using a rectangle in 
the states native SRS (4263) I'm getting the number of states I'm 
expecting. I think they're in the resultscache, and now I'm trying to 
figure out how to get something useful out of that.

Steve Lime wrote:
> What does the corresponding layer definition look like? Are you sure you're grabbing the states
> layer - I mean, have you tried getLayerByName instead?
>
> Steve
>
>   
>>>> On 10/31/2007 at 2:58 PM, in message <4728DE56.3010906 at gisnet.com>, Bill Thoen
>>>>         
> <bthoen at GISNET.COM> wrote:
>   
>> I'm trying to understand how to do querying via PHP mapscript, and I 
>> don't understand the results I'm getting. Basically I'm querying a 
>> polygon layer of US States with a rectangle that intersects 8 states in 
>> the upper midwest. It fully encloses two of these. The following script 
>> seems to find only one result and it says the shapeindex is 42. Now I 
>> know this is the answer to the meaning of life, the universe and 
>> everything, but how do I use this to get a list of the state names that 
>> were found (and why is it only returning 1 found?)
>>
>> What I want to do eventually is display these states on the map in a 
>> highlighting color to show they were selected. If I'm going about this 
>> all wrong, could somebody clue me in?
>>
>>    $rect = ms_newRectObj();
>>    $rect->setextent(-50000, -50000, 50000, 50000);
>>    $lyr = $map->getLayer(1);  // states layer
>>    $results = $lyr->queryByRect($rect);
>>    if ($results == MS_FAILURE) {
>>       echo "Nothing found.<br />";
>>    } else {
>>       echo "Found " . $lyr->getNumResults()."<br />";
>>       for ($i=0; $i<$lyr->getNumResults(); $i++) {
>>          $rcache = $lyr->getResult($i);
>>          echo "   shapeindex: ".$rcache->shapeindex;
>>       }
>>    }
>>    $rect->free();
>>     
>
>   



More information about the mapserver-users mailing list