How to create a new Geodatabase?

1093
2
Jump to solution
10-10-2016 07:28 AM
Highlighted
New Contributor

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

Tags (2)
Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
by Esri Regular Contributor
Esri Regular Contributor

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:

https://github.com/Esri/arcgis-pro-sdk-community-samples/tree/master/Geodatabase/AddDeleteFieldToFro...

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;
            }
        }

View solution in original post

2 Replies
Highlighted
Esri Regular Contributor

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.

Reply
0 Kudos
Highlighted
by Esri Regular Contributor
Esri Regular Contributor

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:

https://github.com/Esri/arcgis-pro-sdk-community-samples/tree/master/Geodatabase/AddDeleteFieldToFro...

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;
            }
        }

View solution in original post