Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

Please help.

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

1 Answer 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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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