Geoprocessing Field Mapping for a Temporary Feature Layer

11-01-2011 10:38 AM
New Contributor
I have a parcel polygon feature class and an attribute table that I want to join together then append to an existing versioned feature class.  I have been able to do this manually in ArcCatalog using tools from the toolbox .  I have also been able to do this with ModelBuilder.  Now I want to do this with VB and ArcObjects.  I am running into problems when I try to map fields for the Append tool.

Here are the steps that I am taking:
1. I execute the Make Feature Layer tool to create a temporary Feature Layer from the parcel polygon feature class (the Add Join tool requires a Feature Layer)
2. Then I execute the Add Join tool on the temporary Feature layer and the attribute table.
3. Finally I execute the Append tool to put the features into the target layer.

I have tried to follow the sample: "Geoprocessing field mapping" but I have been unable to map fields on the temporary Feature Layer.

This line in my code throws an exception:
Dim inputTableA As IDETable = CType(gputilities.MakeDataElement("TempParcelsLayer", Nothing, Nothing), IDETable)

COMException: Error HRESULT E_FAIL has been returned from a call to a COM component.

I would appreciate your help and suggestions with this problem.


Sub JoinPolysAndAttributes()
        ' Initialize the geoprocessor.
        Dim GP As ESRI.ArcGIS.Geoprocessor.Geoprocessor = New ESRI.ArcGIS.Geoprocessor.Geoprocessor()
            ' Set the workspace.
            GP.SetEnvironmentValue("workspace", "Database Connections\UCGIS Direct Gis.sde")

            ' Make a feature layer.
            Dim makefeaturelayer As MakeFeatureLayer = New MakeFeatureLayer("MAIN.live_parcel_polygon", "TempParcelsLayer")  '(in FC, out Temp Layer)
            GP.Execute(makefeaturelayer, Nothing)

            ' Create a temporary join on the feature layer and the attributes table.
            Dim jointable As String = "Database Connections\UCGIS Direct Gis.sde\GIS.TaxParcelAttributes"
            Dim addjoin As AddJoin = New AddJoin("TempParcelsLayer", "serial", jointable, "PARCEL_NO")
            GP.Execute(addjoin, Nothing)     'creates a temporary join that persists for this workspace

            'set up the field mapping since the temporary JoinLayer has different field names than TaxParcel does.
            Dim gputilities As IGPUtilities = New GPUtilitiesClass()  ' Create the GPUtilites object

            'Create a DETable data element object on the temp ParcelsLayer we created above
'This is the line that throws an exception
            Dim inputTableA As IDETable = CType(gputilities.MakeDataElement("TempParcelsLayer", Nothing, Nothing), IDETable)

            ' Create an array of input tables
            Dim inputTables As IArray = New ArrayClass()

            ' Initialize the GPFieldMapping
            Dim fieldmapping As IGPFieldMapping = New GPFieldMappingClass()
            fieldmapping.Initialize(inputTables, Nothing)

            ' Create a new parcelID output field
            Dim parcelidfield As IFieldEdit = New FieldClass()
            parcelidfield.Name_2 = "PARCELID"                               'This field name is in the DESTINATION FC TaxParcel
            parcelidfield.Type_2 = esriFieldType.esriFieldTypeString
            parcelidfield.Length_2 = 12

            ' Create a new FieldMap
            Dim parcelid As IGPFieldMap = New GPFieldMapClass()
            parcelid.OutputField = parcelidfield

            ' Find field map "serial" containing the input field "serial". Add input field to the new field map.
            Dim fieldmap_index As Integer = fieldmapping.FindFieldMap("serial")                'This field name is in the SOURCE FC
            Dim stfid_fieldmap As IGPFieldMap = fieldmapping.GetFieldMap(fieldmap_index)
            Dim field_index As Integer = stfid_fieldmap.FindInputField(inputTableA, "serial")  'This field name is in the SOURCE FC
            Dim inputField As IField = stfid_fieldmap.GetField(field_index)
            parcelid.AddInputField(inputTableA, inputField, 0, 9)

            ' Add the new field map to the field mapping

              ' Now that we have the temporary join (joining polys & attributes) in place we can use the append tool to create the final FC
            Dim appendTool As ESRI.ArcGIS.DataManagementTools.Append = New ESRI.ArcGIS.DataManagementTools.Append()

            ' set the parameter values
            appendTool.inputs = "TempParcelsLayer"
   = "Database Connections\UCGIS Direct Gis.sde\GIS.TaxParcel"
            appendTool.schema_type = "NO_TEST"
            appendTool.field_mapping = fieldmapping

            GP.Execute(appendTool, Nothing)

        Catch ex As ApplicationException
            Console.WriteLine("ApplicationException:  " + ex.Message)
        Catch ex As COMException
            Console.WriteLine("ComException:  " + ex.Message)
        End Try
    End Sub
0 Kudos
0 Replies