Accessing ArcObjects outside of ArcMap, Catalog, etc. and connecting to an SDE db

968
2
09-14-2012 05:13 AM
KevinYanuk
Occasional Contributor
Hello,

I recently began learning ArcObjects (C#), and successfully create a Desktop Add-in with a dockable window. 

My next challenge is to use ArcObjects outside of ESRI software (ArcMap, ArcCatalog, etc.) that will connect and list features in an SDE database connection.

i.e. - A regular windows form with a single button that when clicked, will connect to the SDE, and fill a listbox with the feature classes within it.

Is this possible to use ArcObjects without creating an Add-in?  Any tips on how to perform this simple connect and access to featureclasses is much appreciated!


Thank you,

Kevin
0 Kudos
2 Replies
JohnHauck
Occasional Contributor II
See the discussion here on the Windows Application template in the Choosing an ArcGIS for Desktop project template document. When you use the template you will have GUI options for defining your license and the binding code will be automatically added to the project for you. Once you have handled the proper license initialization and product binding you can start writing the ArcObjects code you need to make use of.

See the Connecting to geodatabases and databases document for some details on how to connect to your enterprise geodatabase. Then you could use something like IWorkspace.DatasetNames or the geoprocessors list methods to get at the feature classes.
0 Kudos
KevinYanuk
Occasional Contributor
*******EDIT********

I figure out everything using the Spatial and Query Filters.


 
   See the discussion here on the Windows Application template in the     Choosing an ArcGIS for Desktop project template document. When you use the template you will have GUI options for defining your license and the binding code will be automatically added to the project for you. Once you have handled the proper license initialization and product binding you can start writing the ArcObjects code you need to make use of.    
  
See the     Connecting to geodatabases and databases document for some details on how to connect to your enterprise geodatabase. Then you could use something like     IWorkspace.DatasetNames or the     geoprocessors list methods to get at the feature classes.  



Thank you very much, I was able to get a handle on my SDE perfectly. I am now a little stuck on my next task: I want to perform a spatial query; the way I had done it before was using IGeometry and ITopologicalOperator's on IFeatures... however, now I am using just Featureclasses.

my code thus far is:

IFeatureWorkspace fws = (IFeatureWorkspace)ws;
                IFeatureDataset opDS = fws.OpenFeatureDataset("Operational");
                IFeatureDataset baseDS = fws.OpenFeatureDataset("Base");
                IEnumDataset opEnum = opDS.Subsets;
                IEnumDataset baseEnum = baseDS.Subsets;
                IDataset opNext = opEnum.Next();
                IDataset baseNext = baseEnum.Next();
                while (baseNext != null)
                {
                    IQueryFilter baseFilter = new QueryFilterClass();
                    IDataStatistics bds = new DataStatisticsClass();
                    IFeatureClass bfc = fws.OpenFeatureClass(baseNext.Name);

                    if (baseNext.Name.Equals("FIELD1")) bds.Field = "FIELD1";
                    else if (baseNext.Name.Equals("FIELD2")) bds.Field = "FIELD2";
                    else
                    {
                        baseNext = baseEnum.Next();
                        continue;
                    }

                    IFeatureCursor bcurs = bfc.Search(null, false);
                    bds.Cursor = (ICursor)bcurs;
                    System.Collections.IEnumerator pEnum = bds.UniqueValues;

                    pEnum.MoveNext();
                    while (pEnum.Current != null)
                    {
                        string f = pEnum.Current.ToString(); 
                        //etc etc
                    }
 


What I would like to do, is put a spatial filter on this featureclass, so I may use it's Geometry as the intersection for another featureclass I want to select from.

The idea is to select features from one featureclass that intersects the above featureclass' field I am getting from "pEnum.Current", and add that unique value into a new field of the selected featureclass. (That is probably a little confusing).

Example:

I have a polygon containing 3 values in a "DISTRICT" field - 1, 2, and 3.
I have a featureclass of points that will fall into one of these polygons.
I want to select all the points in "DISTRICT=1" and add the value of "1" to a new field in the featureclass called "DISTRICT"



*******EDIT********

I figured out everything using the Spatial and Query Filters.
0 Kudos