Hi Sean,
I tried that exact code in 1.2 (with added step to create GDB) and the editOperation returns true (I assume success), but the new field will not populate. It just remains <null>.
I want to edit datastore data, not map data, so went for the callback approach.
See code below:
protected override async void OnClick()
{
//create geodatabase
var cts = new System.Threading.CancellationTokenSource();
var mva = Geoprocessing.MakeValueArray(@"D:\Temp", "Test.gdb");
var result = await Geoprocessing.ExecuteToolAsync("CreateFileGDB_management", mva, null, cts.Token, null, GPExecuteToolFlags.RefreshProjectItems);
//create feature class from template
mva = Geoprocessing.MakeValueArray(@"D:\Temp\Test.gdb", "Test", "POLYGON", templateTablePath);
result = await Geoprocessing.ExecuteToolAsync("CreateFeatureclass_management", mva, null, cts.Token, null, GPExecuteToolFlags.RefreshProjectItems);
//copy selected features from a layer in the map to feature class
mva = Geoprocessing.MakeValueArray(templateTablePath, @"D:\Temp\Test.gdb\Test");
result = await Geoprocessing.ExecuteToolAsync("CopyFeatures_management", mva, null, cts.Token, null, GPExecuteToolFlags.None);
//add field to test feature class
mva = Geoprocessing.MakeValueArray(@"D:\Temp\Test.gdb\Test", "someID", "LONG");
result = await Geoprocessing.ExecuteToolAsync("AddField_management", mva, null, cts.Token, null, GPExecuteToolFlags.None);
//calculate field value with editor callback.
await QueuedTask.Run(() =>
{
using (Geodatabase geodatabase = new Geodatabase(@"D:\Temp\Test.gdb"))
using (FeatureClass featureClass = geodatabase.OpenDataset<FeatureClass>("Test"))
using (FeatureClassDefinition featureClassDefinition = featureClass.GetDefinition())
{
int someIndex = featureClassDefinition.FindField("someID");
EditOperation editOperation = new EditOperation();
editOperation.Callback(context =>
{
using (RowCursor rowCursor = featureClass.Search(null, false))
{
while (rowCursor.MoveNext())
{
using (Feature feature = (Feature)rowCursor.Current)
{
feature[someIndex] = 42;
feature.Store();
}
}
}
}, featureClass);
editOperation.ExecuteAsync();
}
});
MessageBox.Show("Complete");
}
Cheers,
Luke