Select to view content in your preferred language

ArcGIS Pro SDK C#: Copy features from SDE to Project Geodatabase

1196
1
Jump to solution
01-27-2022 10:57 AM
JadedEarth
Frequent Contributor

Hi,

I'm trying to copy a feature class from an SDE geodatabase into my project's default database but it's not working.  Following is my code in C#:

private async void BtnRun_Click(object sender, RoutedEventArgs e)
{
    sdePath = TboxPath.Text;
    in_features = TboxInFeature.Text;
    string url = System.IO.Path.Combine(sdePath, in_features);
    Uri uri = new Uri(url);
    string infc = Path.Combine(sdePath, in_features);
    string outfc = Path.Combine(Project.Current.DefaultGeodatabasePath, lyrName);

    await QueuedTask.Run(() =>
    {
	Geoprocessing.ExecuteToolAsync("CopyFeatures_management", Geoprocessing.MakeValueArray(infc, outfc));
    });
}

 

Then after I copy it to the default geodatabase, I want to load it as a layer on my active map.

Appreciate any help. 

0 Kudos
1 Solution

Accepted Solutions
JadedEarth
Frequent Contributor

Found the solution.  Instead of CopyFeatures_management tool, I used FeatureClassToFeatureClass_conversion tool since I'm dealing with two geodatabases.

Below is the solution.  This copies the feature class to the default project geodatabase from a SQL Server geodatabase and displays it on the active map after copying:

 private async void BtnRun_Click(object sender, RoutedEventArgs e)
{
    string infc = TboxInFeatures.Text;               
    string outputLocation = Project.Current.DefaultGeodatabasePath;
    string outputName = TboxFcName.Text;

    ProgressDialog progDlg = new ProgressDialog("feature Class to Feature Class...", "Cancel", 100, true);
    progDlg.Show();

    IReadOnlyCollection<string> args = Geoprocessing.MakeValueArray(infc, outputLocation, outputName);
    IGPResult gp_result = await Geoprocessing.ExecuteToolAsync("FeatureClassToFeatureClass_conversion", args, null,
                new CancelableProgressorSource(progDlg).Progressor, GPExecuteToolFlags.Default);
}

.  

View solution in original post

0 Kudos
1 Reply
JadedEarth
Frequent Contributor

Found the solution.  Instead of CopyFeatures_management tool, I used FeatureClassToFeatureClass_conversion tool since I'm dealing with two geodatabases.

Below is the solution.  This copies the feature class to the default project geodatabase from a SQL Server geodatabase and displays it on the active map after copying:

 private async void BtnRun_Click(object sender, RoutedEventArgs e)
{
    string infc = TboxInFeatures.Text;               
    string outputLocation = Project.Current.DefaultGeodatabasePath;
    string outputName = TboxFcName.Text;

    ProgressDialog progDlg = new ProgressDialog("feature Class to Feature Class...", "Cancel", 100, true);
    progDlg.Show();

    IReadOnlyCollection<string> args = Geoprocessing.MakeValueArray(infc, outputLocation, outputName);
    IGPResult gp_result = await Geoprocessing.ExecuteToolAsync("FeatureClassToFeatureClass_conversion", args, null,
                new CancelableProgressorSource(progDlg).Progressor, GPExecuteToolFlags.Default);
}

.  

0 Kudos