phpmapscript attributes from ShapefileObj

Dylan Beaudette dylan at IICI.NO-IP.ORG
Mon Aug 22 18:42:07 EDT 2005


Greetings,

Currently I am only able to get attributes for a shape stored within a 
shapfile through a 2 step process:

1. lookup a shape based on the 'contains' method and a for() loop, giving me a 
shape index:
$num_shapes = $shapefile->numshapes;
for($i=0; $i < $num_shapes ; $i++)
    {
    //now extract a single shape
    $this_shape= $shapefile->getShape($i);
    
    //test to see if our point is within the polygon SSURGO bound
    $is_point_in_poly = $this_shape->contains($user_point);
        
    //test for a positive match ($var == 1)
    if($is_point_in_poly == 1)
      {
      //look-up the associated survey name from the shape index
      //can only use that method if getShape is called from a layer object...
      $found_matching_survey_area = true;
      break;    //and break loop
      }

      } //end for loop


2. open a MAP file, open the layer that cooresponds to the previously openend 
shape file, and lookup the attributes associated with a shape id:
$a_layer = $map->getLayerByName('survey-areas');
  $a_layer ->open();
  $a_shape = $a_layer ->getShape(-1, $index);
  $a_shape _attribute= $a_shape ->getvalue($a_layer, 'areasymbol');
  $a_layer ->close();

While this works, it is a little bit awkward - but here is the logic:
1. i am only able to get the number of shapes in a shapfile object... doesn't 
seem to be a method numShapes method for a layer object
2. i am only able to lookup values (attributes) for a shape when getShape is 
called from a layer object.
3. there fore i have to first get a shape id via a shapefile object, then 
lookup the attributes for that shape id via a layer object.

is there a cleaner way to do this, possibly without having to create a MAP 
file?

thanks in advance,

-- 
Dylan Beaudette
Soils and Biogeochemistry Graduate Group
University of California at Davis
530.754.7341



More information about the mapserver-users mailing list