Hi,
Can anyone please tell me how to create a new Geodatabase using the ArcGIS Pro SDK .NET APIs?
I looked at the ProSnippets and several class (inclusing ArcGIS.Core.Data.Geodatabase and ArcGIS.Desktop.Core.Project), but having a hard time to figure it out.
Thank you,
JB
Solved! Go to Solution.
Hi JB,
The ArcGIS.Core.Data API is a DML-only (Data Manipulation Language) API. Schema creation and modification are preformed using the Geoprocessing API.
You can find a sample on how to call a Geoprocessing task from the API here:
To create a File Geodatabase you can use this (button add-in) code snippet:
protected override async void OnClick()
{
var bCreated = await ExecuteAddFileGDB(@"c:\temp\test", @"MyNewFileGDB");
if (bCreated) MessageBox.Show("File GDB Created");
}
private async Task<bool> ExecuteAddFileGDB(string fileGdbPath, string fileGdbName)
{
try
{
return await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
var fGdbPath = fileGdbPath;
var fGdbName = fileGdbName;
var fGdbVersion = "Current"; // create the 'latest' version of file Geodatabase
System.Diagnostics.Debug.WriteLine($@"create {fGdbPath} {fGdbName}");
var parameters = Geoprocessing.MakeValueArray
(fGdbPath, fGdbName, fGdbVersion);
var cts = new CancellationTokenSource();
var results = Geoprocessing.ExecuteToolAsync("management.CreateFileGDB", parameters, null, cts.Token,
(eventName, o) =>
{
System.Diagnostics.Debug.WriteLine($@"GP event: {eventName}");
});
return true;
});
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
return false;
}
}
Hi JB,
Creations\Modifications of a geodatabase are supported through the Geoprocessing API by using the Data Management tools.
The FAQ section has more information on this.
Thanks
Uma Harano
ArcGIS Desktop SDK Team.
Hi JB,
The ArcGIS.Core.Data API is a DML-only (Data Manipulation Language) API. Schema creation and modification are preformed using the Geoprocessing API.
You can find a sample on how to call a Geoprocessing task from the API here:
To create a File Geodatabase you can use this (button add-in) code snippet:
protected override async void OnClick()
{
var bCreated = await ExecuteAddFileGDB(@"c:\temp\test", @"MyNewFileGDB");
if (bCreated) MessageBox.Show("File GDB Created");
}
private async Task<bool> ExecuteAddFileGDB(string fileGdbPath, string fileGdbName)
{
try
{
return await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
var fGdbPath = fileGdbPath;
var fGdbName = fileGdbName;
var fGdbVersion = "Current"; // create the 'latest' version of file Geodatabase
System.Diagnostics.Debug.WriteLine($@"create {fGdbPath} {fGdbName}");
var parameters = Geoprocessing.MakeValueArray
(fGdbPath, fGdbName, fGdbVersion);
var cts = new CancellationTokenSource();
var results = Geoprocessing.ExecuteToolAsync("management.CreateFileGDB", parameters, null, cts.Token,
(eventName, o) =>
{
System.Diagnostics.Debug.WriteLine($@"GP event: {eventName}");
});
return true;
});
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
return false;
}
}