Problems with ms_newFeatureObj in PHP3 MapScript

Martin Lowry m.lowry at medschool.hull.ac.uk
Wed Feb 14 10:39:21 EST 2001


Hi All,

I've been struggling for a while now to make automatic inline feature
addition work, but with no success.  Maybe somebody can tell me what's
wrong with the following script.


    $qry = "SELECT * FROM FieldData";
    $qry .= " WHERE ID=".$id;
    $qry .= " ORDER BY 1,2,3";

    $result = mysql_query($qry, $conn);
    if ($result):

      // Load MapScript module.
      dl("php_mapscript.so");

      // Load MapServer .map file
      $map = ms_newMapObj("NW_Arg.map");

      // Get a handle to the 'Sites' layer
      // The layer properties are defined in the map file
      $lyr_Sites = $map->getLayerByName("sites");

      // Add a feature for every record in the result set
      // The result set will contain about 20 rows
      while ( $row = mysql_fetch_array($result) ):

          $lng = (double)$row["Lng"];
          $lat = (double)$row["Lat"];
           .....
          $line = ms_newLineObj();
          $retval = $line->addXY($lng, $lat);
          $feature = ms_newFeatureObj($lyr_Sites);
          $retval = $feature->shape->add($line);      // $retval is
always 0, i.e. success
          $feature->set("text", "H".$row["FieldNo"]);
      endwhile;
      mysql_free_result($result);

      $lyr_Sites->set("status", 1);
      .....
      $img = $map->draw();
      $url = $img->saveWebImage(0, 0);
      printf("<IMG SRC=%s WIDTH=%d HEIGHT=%d><BR>\n", $url, $map->width,
$map->height);
      .....
   endif;

The problem now shows itself, viz: even though there may be 20 entries
in the result set ONLY ONE ever appears on the map image! The one that
does appear is ALWAYS the first in the result set. (I've even used
$map->Save("/some/file/name.map") with the same result, the "sites"
layer only contains one FEATURE element.  I have a feeling that
ms_newFeatureObj() is not properly linking the new feature into the
layer->features linked list.

To see this in action, go to
http://www.med-phys.hull.ac.uk/~Lobivia/Search.php3?id=1150 and click
the 'Show Map' link.  All the sites under Field Data should be plotted
but only the first is seen!

Any help would be greatly appreciated.
-- 
------------------------------------------------------------------------------
Martin Lowry                            Voice: +44 (0)1482 674075
                               Fax:   +44 (0)1482 320137
                      Email: mailto:m.lowry at medschool.hull.ac.uk
   WWW  : http://www.med-phys.hull.ac.uk/~martin/Lobivia
-------------------------------------------------------------------------------



More information about the mapserver-users mailing list