[GIS] ArcMap Addin – add interoperability connection programatically

add-inarcgis-10.0arcobjectsnetwfs

I'm currently building an add-in for ArcMap – ArcView using the .Net framework.

The user of ArcMap and the Add-in should access data published from WFS services.

I am aware that it is possible to manually add WFS services via the Interoperability Connections interface.

But, is it possible to add these WFS services programatically? (chances are – my users will find it difficult to add these manually)

And if it is, how could it be done?

I can't seem to find any info on this subject.

Best Answer

Unfortunately there is no way to dynamically make requests by a class. You have to program it via the fdl-file. To add a service (like WFS) you could use the code below.

IWorkspaceFactory factory = (IWorkspaceFactory)new FMEWorkspaceFactoryClass();
IFeatureWorkspace workspace = (IFeatureWorkspace)factory.OpenFromFile("d:\test", 0);
IFeatureDataset fds = workspace.OpenFeatureDataset("name.fdl");  

Cheers!

PS: Did you try using the IWFSServer interface? I used DI functionality in one of my previous projects to export data to GML format using QuickExport. You can try using the QuickImport and selecting WFS as the source. I am atatching the QuickExport code for your reference...

    Friend Sub Export2GML()
    Dim pGPMessages As IGPMessages
    'Dim pGPMessage As IGPMessage
    Dim pGPEnvMgr As IGPEnvironmentManager
    Dim pGPEnv_CoordSys As IGPEnvironment
    Dim pGPEnv_Extent As IGPEnvironment
    Dim pGPCOMHelper As IGPComHelper
    Dim pGPToolbox As IGPToolbox
    Dim pGPTool As IGPTool
    Dim pParameter As IGPParameter
    Dim pParameterEdit As IGPParameterEdit
    Dim pDataType As IGPDataType

    Dim pToolboxWorkspaceFactory As IWorkspaceFactory
    Dim pToolboxWorkspace As IToolboxWorkspace
    Dim pParamArray As IArray = New ArrayClass
    Dim pProgressTracker As ITrackCancel
    Dim pDSNames As IEnumDatasetName
    Dim pDSN As IDatasetName

    Dim TempWSPath As String = String.Empty
    Dim Inv_Layer_Names As String = String.Empty

    Try
        OS_Layer_Names = String.Empty

        'Get all layer names from the scratch PGDB
        TempWSPath = pTempWS.PathName

        pDSNames = pTempWS.DatasetNames(esriDatasetType.esriDTFeatureClass)
        pDSNames.Reset()

        pDSN = pDSNames.Next
        While Not pDSN Is Nothing
            If pDSN.Name.Contains("X") Or pDSN.Name.Contains("Y") Then
                'If pDSN.Name.Contains("_OS") Then
                ' OS Layers present, export them seperately
                OS_Layer_Names &= TempWSPath & "\" & pDSN.Name & "; "
            Else
                ' Inventory layer
                Inv_Layer_Names &= TempWSPath & "\" & pDSN.Name & "; "
            End If

            pDSN = pDSNames.Next
        End While

        'gputils = New GPUtilities
        pProgressTracker = New TrackCancel

        'Get the environment manager
        pGPCOMHelper = New GpDispatch
        pGPEnvMgr = pGPCOMHelper.EnvironmentManager

        'Set output coordinate system
        pGPEnv_CoordSys = pGPEnvMgr.FindEnvironment("outputCoordinateSystem")
        pGPEnv_CoordSys.Value = pGPEnv_CoordSys.DataType.CreateValue(ArcMap_INSTALL_DIR & "Coordinate Systems\Projected Coordinate Systems\National Grids\Your National Grid.prj")

        'Set extents
        pGPEnv_Extent = pGPEnvMgr.FindEnvironment("extent")
        pGPEnv_Extent.Value = pGPEnv_Extent.DataType.CreateValue("sameAsInput")

        'Create a toolbox workspace factory
        pToolboxWorkspaceFactory = New ToolboxWorkspaceFactory

        'Open toolbox workspace
        pToolboxWorkspace = pToolboxWorkspaceFactory.OpenFromFile(ArcMap_INSTALL_DIR & "ArcToolbox\Toolboxes", 0)

        'Open toolbox by name
        pGPToolbox = pToolboxWorkspace.OpenToolbox("Data Interoperability Tools.tbx")

        'If DI Toolbox is not found, means extensions were not installed
        If pGPToolbox Is Nothing Then
            MsgBox("Data Interoperability Toolbox not found!" & vbCrLf & "Please contact helpdesk.", MsgBoxStyle.Critical)
            Throw New CustomException
        End If

        'Open tool by name
        pGPTool = pGPToolbox.OpenTool("QuickExport")    'You need to use QuickImport

        'Get parameters required for the tool
        pParamArray = pGPTool.ParameterInfo

        If Not (Inv_Layer_Names Is Nothing Or String.IsNullOrEmpty(Inv_Layer_Names) Or Inv_Layer_Names = "") Then
            'Remove trailing ";"
            Inv_Layer_Names = Inv_Layer_Names.Remove(Inv_Layer_Names.LastIndexOf(";"))

            'Set input parameters
            pParameter = pParamArray.Element(0)
            pParameterEdit = pParameter
            pDataType = pParameter.DataType
            pParameterEdit.Value = pDataType.CreateValue(Inv_Layer_Names)

            'Set output parameters
            pParameter = pParamArray.Element(1)
            pParameterEdit = pParameter
            pDataType = pParameter.DataType
            pParameterEdit.Value = pDataType.CreateValue("GMLSF, " & FILE_STORAGE_PATH.Substring(0, FILE_STORAGE_PATH.LastIndexOf(".")) & ".gml")

            'Validate input parameters
            pGPMessages = pGPTool.Validate(pParamArray, True, Nothing)

            'Execute tool for at least inventory layers
            pGPTool.Execute(pParamArray, pProgressTracker, pGPEnvMgr, pGPMessages)
        End If           

    Catch ex As Exception
        Throw New CustomException(ex.Message, ex)
    Finally
        'Release resources           
        pGPMessages = Nothing
        pParameterEdit = Nothing
        pDataType = Nothing
        pParameterEdit = Nothing
        pParameter = Nothing
        pParamArray = Nothing
        pGPTool = Nothing
        pGPToolbox = Nothing
        pToolboxWorkspace = Nothing
        pToolboxWorkspaceFactory = Nothing
        pGPEnv_Extent = Nothing
        pGPEnv_CoordSys = Nothing
        pGPEnvMgr = Nothing
        pGPCOMHelper = Nothing
        pProgressTracker = Nothing
    End Try
End Sub
Related Question