【转帖】ArcEngine连接表join

【转帖】ArcEngine连接表join

http://bbs.esrichina-bj.cn/ESRI/viewthread.php?tid=15012&extra=page%3D2

本例实现的是如何将地图中的一个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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/110441.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • android toast_Android Toast

    android toast_Android ToastandroidtoastToastmessageisusefultoshownotificationforsmalltimeinandroidapp.Inthistutorial,we’lldiscussandimplementandroidToastmessageexample.Toast消息对在Android应用中显示少量通知非常有用。在本教…

    2025年11月7日
    4
  • stream的groupingby_handlemapping

    stream的groupingby_handlemappinggroupingBy用于分组,toMap用于list转map测试代码:1.建一个实体类,测试中用packagecom.xhx.java;/***xuhaixing*2018/7/2021:43**/publicclassStudent{privateStringname;privateStringsex;priva…

    2022年8月20日
    6
  • c酒店管理系统代码_酒店管理系统

    c酒店管理系统代码_酒店管理系统主要功能:1.添加员工信息2.显示员工信息3.删除员工信息4.修改员工信息5.查找员工信息6.员工信息排序7.清空数据(1)显示数据(2)修改数据(3)查找数据(4)信息排序部分代码展示:workerManager.cpp。需要完整代码可以留邮箱,有时间就发#include”stdafx.h”#include”work…

    2022年9月24日
    1
  • rpm 安装及更新

    rpm 安装及更新安装rpmsudorpm-ivh/Users/aaa.bbb/rpmbuild/RPMS/x86_64/worker-0.0.1-1.x86_64.rpm–force–prefix=/home/chroot/最后prefix是指定安装路径,如果不指定,就是在根目录/rpm-qa|grept-server…

    2022年6月9日
    49
  • FLAG_ACTIVITY_CLEAR_TOP的使用

    FLAG_ACTIVITY_CLEAR_TOP的使用本例使用FLAG_ACTIVITY_CLEAR_TOP退出整个应用程序:多activity中退出整个程序,例如从A->B->C->D,这时我需要从D直接退出程序。补充:finish()和system(0)都只能退出单个activity。我们知道Android的窗口类提供了历史栈,我们可以通过stack的原理来巧妙的实现,这里我们在D窗口打开A窗口时在Intent中直接加入标志Int

    2022年7月17日
    12
  • Linux makefile 教程 很具体,且易懂

    Linux makefile 教程 很具体,且易懂

    2021年9月1日
    53

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号