zoukankan      html  css  js  c++  java
  • ArcEngine连接表join

    ArcEngine连接表join

    本例实现的是如何将地图中的一个FeatureLayer的属性表与另一个数据文件建立连接。
    l   要点
    首先需要定义两个ITable接口对象,分别用来获得地图中的属性表和需要连接的数据文件,再通过IMemoryRelationshipClassFactory.Open方法将两个ITable接口对象根据某个关键字段建立连接,
    最后使用IDisplayRelationshipClass.DisplayRelationshipClass方法将显示该连接
    主要用到IMemoryRelationshipClassFactory接口,IRelationshipClass接口和IDisplayRelationshipClass接口。
    l   程序说明
    函数Join是将当前激活的地图中名称为sLayerName的图层和路径为sFilePath、文件名为sFileName的文件按字段名为sFieldName的字段进行连接。
    l   代码
    Private Function Join(ByVal sLayerName As String, ByVal sFilePath As String, _ByVal sFileName As String, ByVal sFieldName As String) As Boolean
        Dim pMxDocument                     As IMxDocument
        Dim pMap                            As IMap
        Dim pWorkspaceFactory               As IWorkspaceFactory
        Dim pWorkspace                      As IWorkspace
        Dim pFeatureWorkspace               As IFeatureWorkspace
        Dim pFeatureLayer                   As IFeatureLayer
        Dim pFeatureClass                   As IFeatureClass
        Dim pPrimaryTable                   As ITable
        Dim pForeignTable                   As ITable
        Dim pDisplayTable                   As IDisplayTable
        Dim pMemoryRelationshipCF           As IMemoryRelationshipClassFactory
        Dim pRelationshipClass              As IRelationshipClass
        Dim pDisplayRelationshipC           As IDisplayRelationshipClass
        Dim nNumber                         As Integer
        Dim sForeignFile                    As String
    On Error GoTo ErrorHandler:
        Join = False
        sForeignFile = Dir(sFilePath & """ & sFileName)
        If (sForeignFile = "") Then
            MsgBox "The ForeignFile is not exist."
            Exit Function
        End If
        Set pWorkspaceFactory = New ShapefileWorkspaceFactory
        Set pWorkspace = pWorkspaceFactory.OpenFromFile(sFilePath, 0)
        Set pFeatureWorkspace = pWorkspace
        Set pForeignTable = pFeatureWorkspace.OpenTable(sFileName)
        Set pMxDocument = ThisDocument
        Set pMap = pMxDocument.FocusMap
        For nNumber = 0 To pMap.LayerCount - 1
            If pMap.Layer(nNumber).Name = sLayerName Then
                Set pFeatureLayer = pMap.Layer(nNumber)
                Exit For
            End If
        Next
        If pFeatureLayer Is Nothing Then
            MsgBox "No Layer's Name is " & sLayerName
            Exit Function
        End If
        Set pDisplayTable = pFeatureLayer
        Set pFeatureClass = pDisplayTable.DisplayTable
        Set pPrimaryTable = pFeatureClass
        Set pMemoryRelationshipCF = New MemoryRelationshipClassFactory
        Set pRelationshipClass = pMemoryRelationshipCF.Open("TabletoLayer", pPrimaryTable, sFieldName, _
                        pForeignTable, sFieldName, "forward", "backward", esriRelCardinalityOneToOne)
        Set pDisplayRelationshipC = pFeatureLayer
        pDisplayRelationshipC.DisplayRelationshipClass pRelationshipClass, esriLeftOuterJoin
        Join = True
        Exit Function
    ErrorHandler:
        MsgBox Err.Description
    End Function
    Private Sub UIButtonControl1_Click()
        Dim pVBProject              As VBProject
    On Error GoTo ErrorHandler:
        Set pVBProject = ThisDocument.VBProject
        Join "WorldCountries", pVBProject.FileName & ""..".."..".." & ""data", "Continents.dbf", "FID"
        Exit Sub
    ErrorHandler:
        MsgBox Err.Description
    End Sub
  • 相关阅读:
    SAMBA服务和FTP服务讲解(week3_day1)--技术流ken
    Linux网络技术管理及进程管理(week2_day4)--技术流ken
    RAID磁盘阵列及CentOS7系统启动流程(week2_day3)--技术流ken
    Linux磁盘管理及LVM讲解(week2_day2)--技术流ken
    Linux计划任务及压缩归档(week2_day1)--技术流ken
    Linux权限管理(week1_day5)--技术流ken
    Linux高级命令进阶(week1_day2)--技术流ken
    k8s集群监控(十一)--技术流ken
    k8s部署使用Dashboard(十)--技术流ken
    k8s应用机密信息与配置管理(九)--技术流ken
  • 原文地址:https://www.cnblogs.com/lauer0246/p/1308605.html
Copyright © 2011-2022 走看看