Save edits for a single feature class in an Edit Operation with edits in multiple feature classes

288
3
11-21-2023 11:34 AM
KarenMeinstein
Occasional Contributor

Let's say I have an edit operation going and there are edits in multiple features classes, but I only want to save the edits in one of the feature classes.  Is there a way to do this?  Project.Current.SaveEditsAsync() saves the edits to all of the feature classes, which I don't want to do.

0 Kudos
3 Replies
VedantBajaj
Esri Contributor

Hi KarenMeinstein,

If you are using Edit Operations on Pro SDK, you can use the Execute() method to save edits.

Sample Code:

 

   var polyLayer = MapView.Active.Map.GetLayersAsFlattenedList().First((l) => l.Name == "Polygons") 
      as FeatureLayer;
   var polygon = .... ;  //New polygon to use

   //Define some default attribute values
   Dictionary<string,object> attributes = new Dictionary<string, object>();

   attributes["SHAPE"] = polygon;//Geometry

   attributes["Name"] = string.Format("Poly {0}", ++count);
   attributes["Notes"] = string.Format("Notes {0}", count);

   //Create the new feature
   var op = new EditOperation();
   op.Name = string.Format("Create {0}", polys.Name);
   op.Create(polyLayer, attributes);
   if (!op.IsEmpty)
   {
     var result = await op.ExecuteAsync();
     if (!result) //Can also use if (!op.IsSucceeded)
      //TODO: get the op.ErrorMessage, inform the user
   }

You can also use inspector class if you are editing attributes of selected features.

To get more familiar with how editing works in Pro SDK, you can read some text here: https://github.com/Esri/arcgis-pro-sdk/wiki/ProConcepts-Editing

You can also look at some code snippets of the editing functionality here.

 

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

If you use EditOperation your changes and additions end up in undo/redo stacks and the data is not saved until Project.SaveEditsAsync is called.  The ArcGIS Pro API doesn't support selective saving of changes in the undo/redo stacks.  You can't select the changes in one feature class and leave other changes on the redo/undo stack.  

If you have edits to a particular featureclass you could try Geodatabase.ApplyEdits as documented here:  ProConcepts Geodatabase · Esri/arcgis-pro-sdk Wiki (github.com)

ApplyEdits is only recommended for "Editing in stand-alone mode" but last time i tried it works on Add-ins as well.  I think this is the only option for your particular use case.

 

 

0 Kudos
KarenMeinstein
Occasional Contributor

Hi Wolf,

Thanks for your reply.  I will give Geodatabase.ApplyEdits a try.  Alternatively, is it possible to make changes to the undo/redo stack, i.e, remove the edits I don't want to save?

0 Kudos