Select to view content in your preferred language

Layers reference from Geoprocessing

3761
2
Jump to solution
05-29-2015 01:56 PM
AbelPerez
Frequent Contributor

ArcGIS 10.1: I am using ArcObjects in .NET with some geoprocessing. It works great. There is an option to add the resulting feature class to the map. That works great too. However how do I get a reference to this layer to move it to a group layer?

                Dim GP As GeoProcessor = New GeoProcessor

                GP.AddOutputsToMap = True 'True if we want to add outputs to map, False if we dont.

                Dim parameters As IVariantArray = New VarArray

                parameters.Add(inDatasets)     

                parameters.Add(toPointFullName)

                parameters.Add("")             

                Dim res As IGeoProcessorResult = GP.Execute("Merge_management", parameters, Nothing)

                'todo: how do I get a reference to ILayer of the resulting layer added to map?

Thanks

~AGP

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

This is a function I use to return something from IGeoProcessorResult

    Friend Function ReturnObjectfromResult(ByVal result As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2, ByVal Type As String) As Object

        Dim GPVal As ESRI.ArcGIS.Geodatabase.IGPValue
        Dim InMemFC As String
        Dim GPUtil As ESRI.ArcGIS.Geoprocessing.IGPUtilities3 = New ESRI.ArcGIS.Geoprocessing.GPUtilities

        Try
            GPVal = result.GetOutput(0)
            InMemFC = GPVal.GetAsText()

            Select Case Type
                Case "Feature Class"
                    Return GPUtil.OpenFeatureClassFromString(InMemFC)
                Case "Table"
                    Return GPUtil.OpenTableFromString(InMemFC)
                Case "Feature Layer"
                    Return GPUtil.OpenFeatureLayerFromString(InMemFC)
                Case Else
                    Return Nothing
            End Select

        Catch ex As Exception
            System.Windows.Forms.MessageBox.Show(ex.ToString, "ReturnObjectfromResult error")
            Return Nothing
        End Try

    End Function

View solution in original post

0 Kudos
2 Replies
KenBuja
MVP Esteemed Contributor

This is a function I use to return something from IGeoProcessorResult

    Friend Function ReturnObjectfromResult(ByVal result As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2, ByVal Type As String) As Object

        Dim GPVal As ESRI.ArcGIS.Geodatabase.IGPValue
        Dim InMemFC As String
        Dim GPUtil As ESRI.ArcGIS.Geoprocessing.IGPUtilities3 = New ESRI.ArcGIS.Geoprocessing.GPUtilities

        Try
            GPVal = result.GetOutput(0)
            InMemFC = GPVal.GetAsText()

            Select Case Type
                Case "Feature Class"
                    Return GPUtil.OpenFeatureClassFromString(InMemFC)
                Case "Table"
                    Return GPUtil.OpenTableFromString(InMemFC)
                Case "Feature Layer"
                    Return GPUtil.OpenFeatureLayerFromString(InMemFC)
                Case Else
                    Return Nothing
            End Select

        Catch ex As Exception
            System.Windows.Forms.MessageBox.Show(ex.ToString, "ReturnObjectfromResult error")
            Return Nothing
        End Try

    End Function
0 Kudos
AbelPerez
Frequent Contributor

Thanks. I think this will work although I have to set the GP.AddOutputsToMap = False otherwise it will get added twice.