ArcGIS Pro Add-In: How to load spatial SQL Server table to project's active map using C#?

710
2
Jump to solution
01-14-2022 04:39 AM
JadedEarth
Occasional Contributor

I'm new to ArcGIS Pro SDK. I have an Add-in app that performs queries, joins etc. using SQL Server
databases.  There are multiple databases, tables, and joins involved so I use SQL Server environment to perform all the query, search, and join operations.

After all queries are done, I want to display the resulting spatial table on the ArcGIS Pro project map (result is basically a polygon shapefile).

However, although SQL Server table has shape, it doesn't have a spatial reference. I want to use
Albers Equal Area Conic-USGS (I think it has a spatial reference SR_wkid = 6703).

How do I load the spatial SQL Server table (with spatial reference) onto the Active map using C# from my Add-In app?  I have created a database connection to the SQL Server database.  So my parameters look like this:

srcPath = "E:\WorkingFolder\MyAddIn\GISTMPConnection.sde";
in_features = "APEX_SWAT_COMP_HUC8";
out_layer = "ApexSwatCompare_layer";

 

Appreciate any help.

0 Kudos
1 Solution

Accepted Solutions
GKmieliauskas
Esri Regular Contributor

Hi,

How to create featurelayer you can find in ArcGIS Pro SDK Snippets

string url = @"E:\WorkingFolder\MyAddIn\GISTMPConnection.sde\ApexSwatCompare_layer";
Uri uri = new Uri(url);
await QueuedTask.Run(() => LayerFactory.Instance.CreateLayer(uri, MapView.Active.Map));

View solution in original post

0 Kudos
2 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

How to create featurelayer you can find in ArcGIS Pro SDK Snippets

string url = @"E:\WorkingFolder\MyAddIn\GISTMPConnection.sde\ApexSwatCompare_layer";
Uri uri = new Uri(url);
await QueuedTask.Run(() => LayerFactory.Instance.CreateLayer(uri, MapView.Active.Map));
0 Kudos
JadedEarth
Occasional Contributor

Hi,

Thank you.  I encountered "two-step" errors:

1.  First, my connections string for the sde was wrong.  The correct one was (I renamed the table fearing I was encountering character limit in my name):

    string url = @"E:\WorkingFolder\SWATAddIn\MGConnection.sde\MG.dbo.AxSwCompare";

The dot-dbo notation should be specified:  "\databaseName.dbo.tableName".

2.  Next, the table in sde geodatabase didn't have OBJECTIDs, so ArcGIS Pro was throwing an exception.  I have to modify the SQL Server table to add OBJECTIDs as IDENTITY-type.

It was able to load the shapefile after I did the above.

 

Thanks for the link.  It was very helpful.  I couldn't have found them on my own.

 

0 Kudos