Fwd: [UMN_MAPSERVER-USERS] How to edit attribute of a selected shape?

Xiaonan Zhang xnzhang11 at GMAIL.COM
Tue Jan 31 09:25:43 EST 2006


Hi Skalaski,

Thanks for the code. I tried it but it didn't work. There are errors when
change the db file I think. Please see my code used. Also could you please
give me the code of the html input. I have to done this very soon otherwise
I will not ask this.

            /*
-------------------------------------------------------------------- */
      /* check if it's the comment button which is pressed               */
      /*                                  */
      /*
-------------------------------------------------------------------- */
       else if ($HTTP_FORM_VARS["CMD"] == "COMMENT")
          {
              $oPixelPos = ms_newpointobj(); // to record the click position


              if ($HTTP_FORM_VARS["INPUT_TYPE"])
            {
          $szCoord = strval($HTTP_FORM_VARS["INPUT_COORD"]);
          $szCoordType = strval($HTTP_FORM_VARS["INPUT_TYPE"]);
          if (strcmp($szCoordType,"auto_point") == 0)
          {
            $szCoordArray =explode(",", $szCoord);
            $nClickPixX = $szCoordArray[0];
            $nClickPixY = $szCoordArray[1];
          }
          } //Get the point screen location


          //Covert to geo-location
          $nClickGeoX = GMapPix2Geo($nClickPixX, 0, $dfWidthPix,
                 $dfMinX, $dfMaxX, 0);
            $nClickGeoY = GMapPix2Geo($nClickPixY, 0, $dfHeightPix,
                 $dfMinY, $dfMaxY, 1);

            //Create a new comment point
            $oClickGeo = ms_newPointObj();
            $oClickGeo->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);
          //print_r($shape->values);

          //$shape->set ($shape->values["Comment"], "neweddddd"); // change
the comment attributes
          //$shape->values["Comment"]= "neweddddd";


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

          //change the comment attribue here
          //$newArr= array(1,1,comment);
          //$shape->set(values, $newArr); //error, values is not a property

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


          //Task1: input the new comment
          //Method1:Input form
          Printf( "
               <input TYPE='text' NAME=\"new_comment\" value='Please add you
comment here!' size =80>
               <input TYPE='submit' value='Add'>");

          //end of method1

          //Metod 2:pop up a window for user to input comments

          //Printf("The new comment is %f<BR>\n",$_GET['new_comment']);


          //Save the changes
            //$cmmShapefile = "../htdocs/e_Salford/data/comments";
          $objShapefile = ms_newShapeFileObj(
'../htdocs/e_Salford/data/comments', -2 );
          $dbname= "C:/ms4w/Apache/htdocs/e_Salford/data/comments.dbf";
          $db = dbase_open($dbname, 2);
          $nf = dbase_numfields($db);
           $rn = dbase_numrecords ($db);

           $vatr =array("new comment here", 1) ;

           if (ereg("([0-9]+)", $HTTP_FORM_VARS["new_comment"], $vatr))
           {
            $def = array($vatr[0]);
           }
           else
           {
            $def = array($rn+1);
           }

           $objShapefile->addPoint($oClickGeo);
           dbase_add_record($db, $def);

           dbase_close ($db);

           $objShapefile->free();
           $oClickGeo->free();

regards

Jonathan


On 27/01/06, Skalski Artur - askals <Artur.Skalski at acxiom.com> wrote:
>
> OK this is a part of the php code I used to add point to shp, notice to
> use it you have to first give an attribute value (fill a html input) which
> you will save in a dbf. file, than click on a map to add this point (I was
> using previously created blank shp. file)
> ad here is the code:
>
> else if ($HTTP_FORM_VARS["CMD"] == "INPUT_POINT")
>  {
>   $nClickGeoX = GMapPix2Geo($nClickPixX, 0, $dfWidthPix,
>            $dfMinX, $dfMaxX, 0);
>   $nClickGeoY = GMapPix2Geo($nClickPixY, 0, $dfHeightPix,
>            $dfMinY, $dfMaxY, 1);
>
>   $oPoint = ms_newPointObj();
>   $oPoint->setXY($nClickGeoX, $nClickGeoY);
>
>   $oshpfile = ms_newShapefileObj('C:\Program Files\Apache
> Group\Apache2\htdocs\data\siedlce\ptk', -2);
>
>   $dbname = "C:/Program Files/Apache
> Group/Apache2/htdocs/data/siedlce/ptk.dbf";
>
>
>   $db = dbase_open ( $dbname,2);
>
>   $nf = dbase_numfields($db);
>   $rn = dbase_numrecords ($db);
>
>   if (ereg("([0-9]+)", $HTTP_FORM_VARS["atrybuty"], $vatr))
>   {
>    $def = array($vatr[1]);
>   }
>   else
>   {
>    $def = array($rn+1);
>   }
>
>   $oshpfile->addPoint($oPoint);
>   dbase_add_record($db, $def);
>
>   dbase_close ($db);
>
>   $oshpfile->free();
>   $oPoint->free();
> }
>
> usig this i never had any problem with overwriting allready added points,
> no such thing happened
>
> hope this helps
>
> regards
>
> Artur Skalski
>
> *ACXIOM Polska*
> Telephone:      (+48 22) 606 11 27      Budynek Saturn
> Facsimile:      (+48 22) 606 11 28      Domaniewska 41
> Mobile:         (+48) 503 070 036       02-672 Warszawa
> E-mail:         artur.skalski at acxiom.com
>
> -----Original Message-----
> *From:* Xiaonan Zhang [mailto: xnzhang11 at gmail.com]
> *Sent:* Thursday, January 26, 2006 12:59 PM
> *To:* Skalski Artur - askals
> *Cc:* MAPSERVER-USERS at LISTS.UMN.EDU
> *Subject:* Re: [UMN_MAPSERVER-USERS] How to edit attribute of a selected
> shape?
>
> hi, Skalski,
>
> Thanks for the reply. However could you please give more information on
> this. Maybe an example.
>
> The code was working partly ok, the new point can be added, however as I
> said, it will overwrite the old one. It's attribute was inherited from the
> old one. I now want to change it's attribute and when I
> use  $poLayer->getResult(0); there seems not point was picked up.
>
> regards,
>
> Jonathan
>
>
>
> On 26/01/06, Skalski Artur - askals <Artur.Skalski at acxiom.com > wrote:
> >
> > To change an attribute of added point You have to also update a dbase
> > file (I don't see that in your code) wihich stores all atributes of shapes
> > in shp.file, otherwise you get nothing. And if you try to open such a
> > file in ArcViwe it will promt taht tha file was damaged which is because
> > dbf. file record number doesn't mach shp. file record number.
> > dbase.dll which is used to create and update dbf. file comes with
> > standard distribution off all lates php binaries
> >
> > ragards
> >
> > Artur Skalski
> >
> > *ACXIOM Polska*
> > Telephone:      (+48 22) 606 11 27      Budynek Saturn
> > Facsimile:      (+48 22) 606 11 28      Domaniewska 41
> > Mobile:         (+48) 503 070 036       02-672 Warszawa
> > E-mail:         artur.skalski at acxiom.com
> >
> > -----Original Message-----
> > *From:* UMN MapServer Users List [mailto: MAPSERVER-USERS at LISTS.UMN.EDU]
> > *On Behalf Of *Xiaonan Zhang
> > *Sent:* Wednesday, January 25, 2006 6:02 PM
> > *To:* MAPSERVER-USERS at LISTS.UMN.EDU
> > *Subject:* [UMN_MAPSERVER-USERS] How to edit attribute of a selected
> > shape?
> >
> > 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
> >
> >
> >
> > ***************************************************************************
> > The information contained in this communication is confidential, is
> > intended only for the use of the recipient named above, and may be legally
> > privileged.
> >
> > If the reader of this message is not the intended recipient, you are
> > hereby notified that any dissemination, distribution or copying of this
> > communication is strictly prohibited.
> >
> > If you have received this communication in error, please resend this
> > communication to the sender and delete the original message or any copy
> > of it from your computer system.
> >
> > Thank You.
> > ****************************************************************************
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapserver-users/attachments/20060131/0da29a1d/attachment.html


More information about the mapserver-users mailing list