getting extents for displaying individual states

G-Net Consulting joelf at GNETCONSULTING.COM
Wed Sep 8 15:15:49 EDT 2004


Hello list:

I'm attempting to do the same thing, but keep hitting a hurdle,
and have yet to find a solution in the archives.  Here's my code:

// get our state layer
  $stLayer = $gmfMap->getLayer(1);
  $stLayer->set("status", MS_ON);

  // query the passed state
  $qryLayer = $stLayer->queryByAttributes("STATE", $_GET["state"],
MS_MULTIPLE);

  // find out how many results we found
  $shpCount = $stLayer->GetNumResults();

  // open the layer
  $stLayer->open();

  // find out how many results we found
  for ($i = 0; $i < $shpCount; $i++) {
   // get the results we need from the layer
   $result = $stLayer->getResult($i);

   // get our shape info from the index
   $shpData = $stLayer->getShape($result->tileindex, $result->shapeindex);

      print_r($result);
      // ... (do something with the result)
  }

When I get to the getShape() function, I get an error saying "Invalid
feature id."
I know it has to be something simple.  I, too, am trying to get the extents
for
a passed state to "zoom" into it.  Layer #1 is my states layer.

I'm using PHP/MapScript (4.x+ versions).

TIA!

Joel

----- Original Message -----
From: "Eric Bridger" <eric at GOMOOS.ORG>
To: <MAPSERVER-USERS at lists.umn.edu>
Sent: Monday, August 30, 2004 4:36 PM
Subject: Re: [UMN_MAPSERVER-USERS] getting extents for displaying individual
states


> On Mon, 2004-08-30 at 13:20, Bob Cook wrote:
>> I'm working with a map of the entire United States (including Alaska,
>> Hawaii, and other US territories).
>>
>> I would like to allow users to select an individual state (or territory)
>> from a dropdown list and have the map center around that state, and zoom
>> in to it.
>>
>> Is there any easy way of programmatically setting my map's extents
>> (without simply hard-coding extents for each state) so that it centers
>> on one state?
>>
>> I'm using PHP/Mapscript.
>>
>
> Assuming all your states are in one layer you will need to execute an
> attribute  query against the layer based on the name of the state
> entered.($layer->queryByAttrbute()) The query results will give you
> access to the shape of the state you want. That shape has a bounds
> member which is a rectangle which can be use to set the extent of you
> new map.
> $minx = $shape->{bounds}->{minx};
> etc.
>



More information about the mapserver-users mailing list