How to edit attribute of a selected shape?

Xiaonan Zhang xnzhang11 at GMAIL.COM
Wed Jan 25 12:01:55 EST 2006


Dear all,

I am tring to create a function which can add comment point onto layer
however I got a few problems here:
1. the newly added one always overwrite the existing point so there is
always only one point in that layer.
2. I can not regain the added point.
3. how to change the attribute of the added point, say there is one attribue
called "Comment".

thanks.

My code is:

//Create a new comment point
            $ClickGeo = ms_newPointObj();
            $ClickGeo->setXY($nClickGeoX, $nClickGeoY);

            //printf("ClickGeoX %f<BR>\n",$nClickGeoX);
          //printf("ClickGeoY %f<BR>\n",$nClickGeoY);

          //Add it to the comments layer
          $shape = ms_newShapeObj(MS_SHAPE_POINT);
          $line = ms_newLineObj();
          $line->add($oClickGeo);
          $shape ->add($line);


          $poLayer = $gpoMap->getlayerbyname(comments); //get the layer
"comments"
          $poLayer->open();
          //printf("Layer Name: %f<BR>\n", $poLayer->name);


          $poLayer-> addfeature($shape); //add the new comment point


          //Save the changes
            $cmmShapefile = "../htdocs/data/comments";
          $objShapefile = ms_newShapeFileObj( $cmmShapefile, MS_SHP_POINT );
          $objShapefile->addshape($shape);
          $objShapefile->free;
           $poLayer->close();

          //Task2: Use layer->querybypoint to regain the newly added point
and then change it's comment attribut

          //Task2.1:get the new added comment point
                 $poLayer->querybypoint($oClickGeo, MS_SINGLE, 2);
                 $numResults = $poLayer->getNumResults();
                 printf("Find point: %f<BR>\n", $numResults);

                 $oRes = $poLayer->getResult(0);
                 printf("tileindex: %f<BR>\n", $oRes->tileindex);
                 printf("SHAPEINDEX: %f<BR>\n",
$oRes->shapeindex);
                $oShape = $poLayer->getShape(-1,0); //(-1,-1)
                print_r($oShape->values); //print the keys of the values
array
                $comment = $oShape->Values["Comment"];
                printf("The comment attribute is ---: %f<BR>\n",$comment );
//display comment attribute
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapserver-users/attachments/20060125/0e64e46e/attachment.html


More information about the mapserver-users mailing list