How to edit attribute of a selected shape?

Skalski Artur - askals Artur.Skalski at ACXIOM.COM
Fri Jan 27 04:41:20 EST 2006


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:  <mailto:MAPSERVER-USERS at LISTS.UMN.EDU> 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/20060127/c5cb6056/attachment.html


More information about the mapserver-users mailing list