当前位置:甜馍馍地理信息网 >> 地理信息系统GIS >> 产品教程 >> 正文 >>  [阅读资讯:代码:Arcmap如何连接Coverage文件]

代码:Arcmap如何连接Coverage文件

[ 来源:互联网 | 时间:2007年09月15日 | 收藏本文 ] 【

本例实现的是如何在当前激活的Map中连接一个Coverage文件。使用ArcInfoWorkspaceFactory类实现IWorkSpaceFactory接口对象,用IWorkspaceFactory.Open方法打开一个Workspace,并获得Dataset对象。由于此时的Dataset对象可能有多个Coverage文件,所以要获得IEnumDataset接口对象,通过IEnumDataset.Next方法获得一个Coverage文件,并将其所有的FeatureClass放在IFeatureClassContainer对象中。最后通过IFeatureClassContainer.Class方法获得IFeatureClass接口实例,用IMap.AddLayer方法将要连接的Coverage文件的所有FeatureClass加载到当前激活的Map中。

主要用到IWorkspaceFactory接口,IWorkspace接口,IPropertySet接口,IDataset接口,IEnumDataset接口,IFeatureClassContainer接口。

l   程序说明

函数ConnectCoverageFile将sFilePath指定的ArcInfo Workspace中的名称和sFileName相同的Coverage文件加载到当前激活的Map中。

l   代码

Private Sub ConnectCoverageFile(ByVal sFilePath As String, ByVal sFileName As String)

    Dim pWorkspace                  As IWorkspace
    Dim pWorkspaceFactory           As IWorkspaceFactory
    Dim pPropertySet                As IPropertySet
    Dim pDataset                    As IDataset
    Dim pEnumDataset                As IEnumDataset
    Dim pFeatureClassC              As IFeatureClassContainer
    Dim pFeatureLayer               As IFeatureLayer
    Dim pMxDocument                 As IMxDocument
    Dim pMap                        As IMap
    Dim nNumber                     As Integer
    Dim sWorkspace                  As String

On Error GoTo ErrorHandler:

    sWorkspace = Dir(sFilePath, vbDirectory)
    If (sWorkspace = "") Then
        MsgBox ("文件不存在")
        Exit Sub
    End If

    Set pWorkspaceFactory = New ArcInfoWorkspaceFactory
    Set pPropertySet = New PropertySet

    'canada is an arcinfoworkspace
    pPropertySet.SetProperty "DATABASE", sFilePath

    'pWorkSp is a pointer to the IArcInfoWorkspace
    Set pWorkspace = pWorkspaceFactory.Open(pPropertySet, 0)

    'now get to dataset objects using Idataset
    Set pDataset = pWorkspace

    'use enum to get datasets
    Set pEnumDataset = pDataset.Subsets

    pEnumDataset.Reset

    'use FeatureClassContainer to get datasets
    Set pFeatureClassC = pEnumDataset.Next

    Do While Not pFeatureClassC Is Nothing
        Set pDataset = pFeatureClassC
        If (pDataset.Name <> sFileName) Then
            Set pFeatureClassC = pEnumDataset.Next
        Else
            Exit Do
        End If
    Loop

    'add FeatureClassContainer to map
    If (pFeatureClassC Is Nothing) Then
        MsgBox ("文件不存在")
    Else
        nNumber = 0
        Set pMxDocument = ThisDocument
        Set pMap = pMxDocument.FocusMap
        Do While nNumber < pFeatureClassC.ClassCount
            Set pFeatureLayer = New FeatureLayer
            Set pFeatureLayer.FeatureClass = pFeatureClassC.Class(nNumber)
            pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName
            nNumber = nNumber + 1
            pMap.AddLayer pFeatureLayer
        Loop
    End If

    Exit Sub

ErrorHandler:
    MsgBox Err.Description

End Sub

Private Sub UIButtonControl1_Click()

    Dim pVBProject              As VBProject

On Error GoTo ErrorHandler:

    Set pVBProject = ThisDocument.VBProject
    ConnectCoverageFile pVBProject.FileName & "\..\..\..\.." & "\data\canada", "canada"

    Exit Sub

ErrorHandler:
    MsgBox Err.Description

End Sub

【推荐本文】 【打印本页】 【返回顶部
最新文章
推荐文章