如何在ArcMap中加入Text和dBASE文件
本例实现的是如何在当前的ArcMap中加入Text文件和dBASE文件。
l 要点
首先为Text文件或dBASE文件创建一个与之对应的ITable接口对象,然后通过IMap实例获得IStandaloneTable接口对象和IStandaloneTableCollection接口对象,并设置其属性,最后使用IStandaloneTableCollection.AddStandaloneTable方法将Text文件或dBASE文件加入到当前的ArcMap中。加入Text文件或dBASE文件的区别仅在于创建ITable对象时IWorkspaceFactory的类型不同,加入Text文件时是TextFileWorkspaceFactory类型,加入dBASE文件时是ShapefileWorkspaceFactory类型。
主要用到了IWorkspaceFactory接口,IWorkspace接口,IFeatureWorkspace接口,ITable接口,IStandaloneTable接口和IStandaloneTableCollection接口。
l 程序说明
函数AddTextFile通过文件路径sFilePath和文件名sFileName找到Text文件并为其创建ITable对象
函数AddDBASEFile通过文件路径sFilePath和文件名sFileName找到dBASE文件并为其创建ITable对象
函数Add_Table_TOC将ITable对象pTable加入到当前的ArcMap中。
l 代码
|
Private Sub AddTextFile(ByVal sFilePath As String, ByVal sFileName As String) Dim pWorkspaceFactory As IWorkspaceFactory On Error GoTo ErrorHandler: sDir = Dir(sFilePath & sFileName & ".txt") 'Get the ITable from the geodatabase 'Add the table Exit Sub ErrorHandler: End Sub Private Sub AddDBASEFile(ByVal sFilePath As String, ByVal sFileName As String) Dim pWorkspaceFactory As IWorkspaceFactory On Error GoTo ErrorHandler: 'Get the ITable from the geodatabase 'Add the table Exit Sub ErrorHandler: End Sub Private Sub Add_Table_TOC(pTable As ITable) Dim pDoc As IMxDocument On Error GoTo ErrorHandler: Set pDoc = ThisDocument 'Create a new standalone table and add it 'Refresh the TOC Exit Sub ErrorHandler: End Sub Private Sub UIButtonControl1_Click() Dim pVBProject As VBProject On Error GoTo ErrorHandler: Set pVBProject = ThisDocument.VBProject 'Add text file to ArcMap. Dont include .txt extension 'Add dBASE file to ArcMap Exit Sub ErrorHandler: End Sub |
浙公网安备 33010602011771号