How to pass Table View data type to Append Geoprocessor in VBNET

511
2
05-17-2013 10:59 AM
TimBarker
New Contributor II
Hi,

I have a vbnet component program originally coded around version 9.x.  It successfully used strings to pass input feature names and output feature names to Intersect and Append tools using the geoprocessor approach.  This no longer works in Desktop v10.1.  I get the cryptic HRESULT E_FAIL error.  After much anguish, I discovered it was really throwing error 000628 - it didn't like the data type of the passed in parameter.  Turns out Intersect wants the the input_features in a Value Table data form.  The following code now works for Intersect


Dim GP As Geoprocessor = New Geoprocessor
        GP.AddOutputsToMap = False
        'GP.AddOutputsToMap = True

        GP.OverwriteOutput = True

        GP.LogHistory = True
        'System.Threading.Thread.Sleep(5000)


        'Calculate feature names with paths and put in data types required to pass to the geoprocessor
       
        Dim polygonFileName As String = GolderGISTools.Utilities.Utility.GetLayerPathAndName(modelSetting.PolygonFeatureClassNames(1), Me._mxDocument) & ".shp"
        Dim gpUtils As IGPUtilities2 = New GPUtilitiesClass()
        Dim inFeature1 As IFeatureClass = gpUtils.OpenFeatureClassFromString(modelSetting.OutputDataPath & "\fishnet.shp")
        Dim inFeature2 As IFeatureClass = gpUtils.OpenFeatureClassFromString(polygonFileName)
        'Create and populate a Value Table Object to hold the input features to be intersected
        Dim vt As IGpValueTableObject = New GpValueTableObjectClass()

        vt.SetColumns(1)
        Dim obj1 As Object = inFeature1
        vt.AddRow(obj1)
        Dim obj2 As Object = inFeature2
        vt.AddRow(obj2)
        'Run the Tool
        Dim intersect As ESRI.ArcGIS.AnalysisTools.Intersect = New ESRI.ArcGIS.AnalysisTools.Intersect()
        'Dim union As ESRI.ArcGIS.AnalysisTools.Union = New ESRI.ArcGIS.AnalysisTools.Union()
        intersect.in_features = vt
        intersect.out_feature_class = tempDirectoryInfo.FullName & "\temp.gdb\" & "intersect"
        intersect.join_attributes = "ALL"
        intersect.output_type = "INPUT"


        Try
            GP.Execute(intersect, Nothing)
            intersect = Nothing
            ReturnMessages(GP, modelSetting.OutputDataPath & "\log.txt")
            If GP.MaxSeverity = 2 Then
                MessageBox.Show("Error intersect Fishnet with LT/FT, see log file", "error in ALCES Mapper", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Return False
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, "error intersect Fishnet with LT/FT", MessageBoxButtons.OK, MessageBoxIcon.Error)
            ReturnMessages(GP, modelSetting.OutputDataPath & "\log.txt")
            Return False
        End Try
        intersect = Nothing
        vt = Nothing
        obj1 = Nothing
        obj2 = Nothing


        'While Marshal.ReleaseComObject(intersect) > 0
        'End While
        GC.Collect()
        GC.WaitForPendingFinalizers()



THE PROBLEM / QUESTION:

The Append tool uses a Table View or Raster Feature as the Input and Target parameters.  I have tried many combinations to duplicate the above example with this composite data type.  All I want is to assign two shape files to the input and target parameters so I can execute an append.  I clearly am missing something basic here about the object oriented nomenclature.

Input will be :  tempDirectoryInfo.FullName & "\temp.gdb\" & "intersect1.shp"
Target will be: tempDirectoryInfo.FullName & "\temp.gdb\" & "intersect.shp"

Help??

Tim Barker
Innovative Forest Analytics Ltd
0 Kudos
2 Replies
FridjofSchmidt
Occasional Contributor
Tim,

Apparently the Intersect tool now has an additional "Rank" value that can be optionally set. This seems to have changed the syntax a bit, but I couldn't find an example for use in ArcObjects in the documentation. However, when you run the Intersect tool in interactive mode, you can see that when not entering rank values, some "#" characters are inserted at the end of each input dataset path.

Maybe this will work for you too?
intersect.in_features = pathToFirstInputFeatureClass & " #;" & pathToSecondInputFeatureClass & " #"

Otherwise you'd probably have to set a 2nd column for the value table, but it will also involve setting the right data type for each column etc... too much code in my opinion if you can use a String-based approach.
0 Kudos
KenBuja
MVP Esteemed Contributor
Here's an example of how to add several inputs for the Intersect Tool

ESRI.ArcGIS.Geoprocessor.Geoprocessor GP = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
GP.OverwriteOutput = true;
IGPUtilities2 gpUtils = new GPUtilitiesClass();
IFeatureClass inFeature1 = gpUtils.OpenFeatureClassFromString(@"E:\Test.gdb\states");
IFeatureClass inFeature2 = gpUtils.OpenFeatureClassFromString(@"E:\Test.gdb\us_rivers");
IGpValueTableObject vt = new GpValueTableObjectClass();
//vt.SetColumns(1);
vt.SetColumns(2);
object weight;
weight = 1 as object;
object obj1 = inFeature1;
vt.AddRow(ref obj1);
vt.SetValue(0, 1, ref weight);
object obj2 = inFeature2;
vt.AddRow(ref obj2);
vt.SetValue(1, 1, ref weight);
ESRI.ArcGIS.AnalysisTools.Intersect intersect = new ESRI.ArcGIS.AnalysisTools.Intersect();
intersect.in_features = vt;
intersect.out_feature_class = "E:\testout.shp";
GP.Execute(intersect, null);
0 Kudos