3

I'm always having a problem in GP.execute() when trying to execute this method. Here is my code:

 Friend Function DissolveFeatures(ByVal pInFLayer As ESRI.ArcGIS.Carto.IFeatureLayer, ByVal DissolveField As String, ByVal OutName As String) As ESRI.ArcGIS.Carto.IFeatureLayer

            Dim GP As New ESRI.ArcGIS.Geoprocessor.Geoprocessor
            Dim Dissolve As ESRI.ArcGIS.DataManagementTools.Dissolve = New ESRI.ArcGIS.DataManagementTools.Dissolve
            Dim pFLayer As ESRI.ArcGIS.Carto.IFeatureLayer = New ESRI.ArcGIS.Carto.FeatureLayer

            Try
                GP.AddOutputsToMap = True
                GP.OverwriteOutput = True
                GP.SetEnvironmentValue("workspace", "Database Connections\IFE connexion.sde")

                Dissolve.in_features = pInFLayer
                Dissolve.dissolve_field = DissolveField
                Dissolve.out_feature_class = "Database Connections\IFE connexion.sde\" & OutName

                RunTool(GP, Dissolve, Nothing)


                pFLayer.FeatureClass = CType(GP.Open(OutName), IFeatureClass)
                pFLayer.Name = pFLayer.FeatureClass.AliasName

            Catch ex As Exception
                MsgBox(ex.Message & "Dissolve Features")
            End Try

            Return pFLayer

        End Function


Private Shared Sub RunTool(ByVal geoprocessor As ESRI.ArcGIS.Geoprocessor.Geoprocessor, ByVal process As IGPProcess, ByVal TC As ITrackCancel)

        ' Set the overwrite output option to true
        geoprocessor.OverwriteOutput = True

        Try
            geoprocessor.Execute(process, Nothing)
            ReturnMessages(geoprocessor)

        Catch err As Exception
            Console.WriteLine(err.Message)
            ReturnMessages(geoprocessor)
        End Try
    End Sub



    ' Function for returning the tool messages.
    Private Shared Sub ReturnMessages(ByVal gp As ESRI.ArcGIS.Geoprocessor.Geoprocessor)
        ' Print out the messages from tool executions
        Dim Count As Integer
        If gp.MessageCount > 0 Then
            For Count = 0 To gp.MessageCount - 1
                Console.WriteLine(gp.GetMessage(Count))
            Next
        End If
    End Sub

This returns an error:

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

2
  • this line Dissolve.out_feature_class = "Database Connections\IFE connexion.sde\" & OutName it s not catched by the compiler ?
    – geogeek
    Commented Apr 11, 2013 at 10:44
  • proplem is when he want to execute Geoprocessor on line geoprocessor.Execute(process, Nothing)
    – Mounaim
    Commented Apr 11, 2013 at 13:06

1 Answer 1

1

I solved it. probleme is because you use iFeatureLayer as an input. Use a IFeatureClass.

 Friend Function DissolveFeatures(ByVal pFC As IFeatureClass, ByVal DissolveField As String, ByVal OutName As String) As iFeatureClass

        Dim GP As New ESRI.ArcGIS.Geoprocessor.Geoprocessor
        Dim Dissolve As ESRI.ArcGIS.DataManagementTools.Dissolve = New ESRI.ArcGIS.DataManagementTools.Dissolve

        Try

            Dissolve.in_features = pFC
            Dissolve.dissolve_field = DissolveField
            Dissolve.out_feature_class = "Database Connections\IFE connexion.sde\" & OutName

            RunTool(GP, Dissolve, Nothing)


            pFC.FeatureClass = CType(GP.Open(OutName), IFeatureClass)
            pFC.Name = pFC.FeatureClass.AliasName

        Catch ex As Exception
            MsgBox(ex.Message & "Dissolve Features")
        End Try

        Return pFC

    End Function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.