现在的位置: 首页 > 综合 > 正文

打开coverage中的属性表

2017年10月13日 ⁄ 综合 ⁄ 共 1588字 ⁄ 字号 评论关闭

不经意间看到,兴许对打开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

 

抱歉!评论已关闭.