4 Replies Latest reply on May 1, 2012 11:46 PM by hrithikesh3485

    Can I use extend / Trim of the Geometery Service to Edit a feature?

    hrithikesh3485
      Hi,

      Can i use the example provided by ESRI for extend and trim to work on a feature?
      example is given in interactive sdk :-http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#TrimExtend

      Regards,
      Sameer
        • Re: Can I use extend / Trim of the Geometery Service to Edit a feature?
          JNery-esristaff
          Sure you can. You can update graphic.Geometry to the result you get from GeometryService_TrimExtendCompleted event.

          However, do you mean to do Cut? Editor.Cut is already available. You can try out this sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#EditToolsAutoSave. Select a feature and activate Cut command.
          • Re: Can I use extend / Trim of the Geometery Service to Edit a feature?
            hrithikesh3485
            Sure you can. You can update graphic.Geometry to the result you get from GeometryService_TrimExtendCompleted event.

            However, do you mean to do Cut? Editor.Cut is already available. You can try out this sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#EditToolsAutoSave. Select a feature and activate Cut command.


            Hi,

            Thanks for replying.

            I assigned the obtained graphics but i am getting error - 400 unable to apply edits. I am using SaveEditFailed event to check if it is getting updated. I guess there is issue with the way i am building graphic, i guess there should be attribute which should be associated with the graphic which is causing issue in saving the returned geometry

            below is my code : -
                     void GeometryService_TrimExtendCompleted(object sender, GraphicsEventArgs e)
                    {
                        //getFeatLayer.ClearGraphics();
                        Graphic resultGraphic = null;
                        foreach (Graphic g in e.Results)
                        {
                          
                            g.Symbol = this.Resources["DefaultLineSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
                            resultGraphic = g;
                            //getFeatLayer.Graphics.Add(g);
                            GraphicsLayer TrimGraphicLyr = this.graphicsLayer as GraphicsLayer;
                            //TrimGraphicLyr.ClearGraphics();
                            //TrimGraphicLyr.Graphics.Add(g);
                          
                            getFeatLayer.Graphics.Add(g);
                        }
                          
                             foreach (Graphic g1 in getFeatLayer.SelectedGraphics)
                            {
                                //resultGraphic.Attributes.Add(g1.Attributes.ToArray());

                                foreach (var f in getFeatLayer.LayerInfo.Fields)
                                 {
                                    resultGraphic.Attributes[f.Name] = f.Nullable ? null : "testing";
                                 }

                                 getFeatLayer.Graphics.Remove(g1);

                            }

                          
                   
                            //Editor editor = LayoutRoot.Resources["MyEditor"] as Editor;
                           
                            foreach (GraphicsLayer graphicsLayer in featureEditor.GraphicsLayers)
                            {
                                if (graphicsLayer is FeatureLayer)
                                {
                                    FeatureLayer featureLayer = graphicsLayer as FeatureLayer;
                                    if (featureLayer.HasEdits)
                                        featureLayer.Update();
                                        featureLayer.SaveEditsFailed+=new EventHandler<TaskFailedEventArgs>(featureLayer_SaveEditsFailed);
                                        featureLayer.SaveEdits();
                                        featureLayer.Refresh();

                                }
                            }

                          
                       

                        MyDrawObject.IsEnabled = true;
                    }



                    protected void featureLayer_SaveEditsFailed(object sender, EventArgs e)
                    {
                      
                    }
            • Re: Can I use extend / Trim of the Geometery Service to Edit a feature?
              JNery-esristaff
              TrimExtendAsync() has an overload that takes user token, you can use that instead to pass the original graphics.

              In the completed event you can do

              var originalGraphics = e.UserToken as Graphic[];

              and update each geometry.

              Graphics.Add() adds a new graphic which is not what you want to do. You need to update the existing graphic. Run Fiddler to see the save request (../applyEdits), this should show update instead of add.
              • Re: Can I use extend / Trim of the Geometery Service to Edit a feature?
                hrithikesh3485
                Hi jennifer,

                Thanks for the suggestion,

                I am new to silverlight and did not exactly understand how to use that UserToken.

                I am using c# and i checked GeometryService_TrimExtendCompleted() and it did not had any e.UserToken which i could typecast to Graphic. I am using the same code which has been pasted above can you please paste some sample which will help me do this ?

                Regards,
                Sameer