[GIS] How to connect to ArcSDE for using the ArcObjects Erase tool in C#

arcgis-10.0arcobjectsenterprise-geodatabasegeoprocessingsql

I want to make use of geoprocessing via .NET ArcObjects, in this case of the "Erase" tool. This is easy once dealing with a local gdb file what I did for feasibility study. The issue occurs when I want to work on feature classes of MS SQL ArcSDE database. Normally, all operations are done on a IWorkSpace that is created and opened. Here, this page http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/Working_with_ArcSDE_data/0001000001zs000000/ states that I can either use so called .sde file or property set. So I tried to use the PropertySet I created for the IWorkspace before, but it did not work – it expects IVariantArray. In the aforementioned website, iVariantArray is used to launch a tool that creates the .sde file. There is no description on the order of parameters passed, I can only guess what means what.

Obviously I understand, that I need to pass also the three parameters for Erase tool: in_features,out_feature_class and erase_features. Can someone please explain to me how can I do that?

Am I doing something wrong? I can't understand why is the creation of .sde file described in the topic concerning geoprocessing, while it's clearly missing the description of a second way to connect via property set.

Best Answer

You need to create the SDE connection file in order to reference it when calling your 'erase' geoprocessing tool. For example, if you wanted to pass a SDE feature class to a geoprocessing tool, the path will something along the lines of

<some location>\mySDEConnectionFile.sde\myFeatureClass

But in order to create this SDE connection file (.SDE) you need to use the geoprocessing tool mentioned in the link you provided. This will be the tricky part as there are a lot of parameters to pass in order to create it. But just follow the code example. Here is the link to the page describing the order of parameters passed to the tool:

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//0017000000pt000000

Once you have your SDE connection file created, you can pass it as a parameter to your erase geoprocessing tool, you'll do something like this (sorry it's in VB)

Dim gp As IGeoprocessor = New Geoprocessor
Dim var As IVariantArray = New VarArray()
With var
    .Add(<input features>)
    .Add(mySDEConnectionFile.sde\myFeatureclass)
    .Add(<erase features>)
End With
gp.Execute("EraseTool", var, nothing)

Something similar to that anyway. Do you have a link to the erase tool you're trying to run? I can't find a reference to it.