ArcMap插件-以编程方式添加互操作性连接


10

我目前正在使用.Net框架为ArcMap-ArcView构建外接程序。

ArcMap和外接程序的用户应访问从WFS服务发布的数据。

我知道可以通过“ 互操作连接”界面手动添加WFS服务。

但是,是否可以通过编程方式添加这些WFS服务?(可能是-我的用户会发现很难手动添加这些内容)

如果是的话,怎么办呢?

我似乎找不到有关此主题的任何信息。


1
您是否有公共WFS网站的网址?如果是这样,请继续发布。这样,人们可以在将其包含在答案中之前测试其代码。
Kirk Kuykendall

嗨,我无法发布公共网址-对不起,朋友。
user2847 2011年

1
@ user2847,您好,您是否找到解决方案?谢谢
pvdev

Answers:


1

不幸的是,无法通过类动态地发出请求。您必须通过fdl文件对其进行编程。要添加服务(如WFS),您可以使用以下代码。

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

干杯!

PS:您是否尝试过使用IWFSServer接口?我在以前的项目之一中使用了DI功能,使用QuickExport将数据导出为GML格式。您可以尝试使用QuickImport并选择WFS作为源。我正在获取QuickExport代码,以供您参考...

    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

嗨,谢谢您的回答:)我可能应该已经指定我正在使用arcMap10。从此资源 help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp / ...看来FMEWorkspaceFactory已被删除。从9.3-> 10.0开始。您是否知道使用示例中指定的FMEWorkspaceFactoryClass是否有其他选择?最好的问候/ larssj
user2847

哦...我不知道它已被删除。如果我没记错,那么DI工具箱也将不可用...
ujjwalesri 2011年

好的,队友没问题。谢谢你的帮助。如果找到解决方案,请在此处发布。我现在唯一能想到的就是“幕后”,并添加将服务添加到ArcView所需的fdl文件(如果放置在正确的ArcView目录中,则应将这些文件自动加载到互操作性连接界面中)。对于我的用户来说,这仍然会容易得多。
user2847 2011年
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.