打开coverage中的属性表
2013-09-26 08:35
393 查看
不经意间看到,兴许对打开info表可供参考,便粘过来。上为错误代码,下面为修正的
我用Ifeatureworkspace.opentable 无法实现coverage下属性表的打开,是不是因为coverage的属性表是存放在info文件夹中,所以打开失败,该如何做?我的代码如下:
Public Function OpenTableFromFile(sPath As String, sTableName As String) As ITable
' This function returns an ITable interface pointer from an INFO or DBF file. it will give an
' automation error if table type is not a dbf table or info table
On Error GoTo ERH
Dim pTable As ITable
Dim pWSFact As IWorkspaceFactory
Dim pFeatWork As IFeatureWorkspace
' choice of workspace factory depends if table is INFO or DBF
Dim sSplit() As String
sSplit = Split(sTableName, ".")
If UBound(sSplit) = LBound(sSplit) Then ' no dots in name, assume info table
Set pWSFact = New ArcInfoWorkspaceFactory
Else
If sSplit(1) = "dbf" Then
Set pWSFact = New ShapefileWorkspaceFactory
Else 'not dbf assume info table
Set pWSFact = New ArcInfoWorkspaceFactory
End If
End If
If pWSFact.IsWorkspace(sPath) Then
Set pFeatWork = pWSFact.OpenFromFile(sPath, 0)
Set pTable = pFeatWork.OpenTable(sTableName)
End If
' Return the table pointer
Set OpenTableFromFile = pTable
Exit Function
ERH:
MsgBox "Failed in opening table from file " & Err.Description
End Function
问题已解决,把代码贴出来吧:
Public Function GetTable(pGxObject As IGxObject) As ITable
'Use name objects because they are faster than opening objects
'Coverage featureclasses will return null
On Error GoTo err:
Dim pDatasetName As IDatasetName
Dim pDSType As esriDatasetType
Dim pname As IName
'Check for QI
Dim pArcInfoTable As IArcInfoTable
Set pname = pGxObject.InternalObjectName
If TypeOf pname Is IDatasetName Then
Set pDatasetName = pname
pDSType = pDatasetName.Type
If pDSType = esriDTTable Or pDSType = esriDTFeatureClass Then
Set GetTable = pname.Open
Set pT = GetTable
Exit Function
End If
End If
Exit Function
err:
If err.Number = 13 Then
Resume Next
End If
End Function
我用Ifeatureworkspace.opentable 无法实现coverage下属性表的打开,是不是因为coverage的属性表是存放在info文件夹中,所以打开失败,该如何做?我的代码如下:
Public Function OpenTableFromFile(sPath As String, sTableName As String) As ITable
' This function returns an ITable interface pointer from an INFO or DBF file. it will give an
' automation error if table type is not a dbf table or info table
On Error GoTo ERH
Dim pTable As ITable
Dim pWSFact As IWorkspaceFactory
Dim pFeatWork As IFeatureWorkspace
' choice of workspace factory depends if table is INFO or DBF
Dim sSplit() As String
sSplit = Split(sTableName, ".")
If UBound(sSplit) = LBound(sSplit) Then ' no dots in name, assume info table
Set pWSFact = New ArcInfoWorkspaceFactory
Else
If sSplit(1) = "dbf" Then
Set pWSFact = New ShapefileWorkspaceFactory
Else 'not dbf assume info table
Set pWSFact = New ArcInfoWorkspaceFactory
End If
End If
If pWSFact.IsWorkspace(sPath) Then
Set pFeatWork = pWSFact.OpenFromFile(sPath, 0)
Set pTable = pFeatWork.OpenTable(sTableName)
End If
' Return the table pointer
Set OpenTableFromFile = pTable
Exit Function
ERH:
MsgBox "Failed in opening table from file " & Err.Description
End Function
问题已解决,把代码贴出来吧:
Public Function GetTable(pGxObject As IGxObject) As ITable
'Use name objects because they are faster than opening objects
'Coverage featureclasses will return null
On Error GoTo err:
Dim pDatasetName As IDatasetName
Dim pDSType As esriDatasetType
Dim pname As IName
'Check for QI
Dim pArcInfoTable As IArcInfoTable
Set pname = pGxObject.InternalObjectName
If TypeOf pname Is IDatasetName Then
Set pDatasetName = pname
pDSType = pDatasetName.Type
If pDSType = esriDTTable Or pDSType = esriDTFeatureClass Then
Set GetTable = pname.Open
Set pT = GetTable
Exit Function
End If
End If
Exit Function
err:
If err.Number = 13 Then
Resume Next
End If
End Function
相关文章推荐
- (续)AE中读取所打开shp的属性表
- 直接生成打开窗口代码,不必下载
- OUTLOOK无法打开
- 打开IE8总是提示欢迎使用?怎样使它不提示?
- “我的电脑”打开很慢(手电筒一直在扫描查找)的解决方法
- linux下打开windows txt文件中文乱码问题
- 全屏图片上下打开
- IOS开发判断是否第一次使用软件且下次app自动更新后再次打开还是第一次使用
- linux下在命令行中用默认程序打开特定文件如.mp3 .jpg 甚至是网页也可以
- qt 实现单击按钮打开指定文档
- 关于tomcat首页打不开部署项目能打开的问题解决方法
- PhpStorm在一个窗口打开多个项目
- 提高网页打开速度的一些小技巧
- 打开白盒,开启测试
- 打开和关闭窗口以及窗口间的数据传递
- 苹果设备连接Citrix XenApp服务器,打开应用程序慢的解决方法
- Ubuntu 12.04右键在当前位置打开终端
- iOS开发 - 应用内打开第三方应用并传值
- java实现打开文件和保存文件功能
- c#用run32dll打开系统dll(如系统图片查看器,并置最顶层)