ArcGIS Pro二次开发添加字段
private async Task<bool> ExecuteAddFieldTool(BasicFeatureLayer theLayer, KeyValuePair<string, string> field, string fieldType, int? fieldLength = null, bool isNullable = true) { try { return await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() => { var inTable = theLayer.Name; var table = theLayer.GetTable(); var dataStore = table.GetDatastore(); var workspaceNameDef = dataStore.GetConnectionString(); var workspaceName = workspaceNameDef.Split('=')[1]; var fullSpec = System.IO.Path.Combine(workspaceName, inTable); System.Diagnostics.Debug.WriteLine($@"Add {field.Key} from {fullSpec}"); var parameters = Geoprocessing.MakeValueArray(fullSpec, field.Key, fieldType.ToUpper(), null, null, fieldLength, field.Value, isNullable ? "NULABLE" : "NON_NULLABLE"); var cts = new CancellationTokenSource(); var results = Geoprocessing.ExecuteToolAsync("management.AddField", parameters, null, cts.Token, (eventName, o) => { System.Diagnostics.Debug.WriteLine($@"GP event: {eventName}"); }); return true; }); } catch (Exception ex) { MessageBox.Show(ex.ToString()); return false; } }