CAD Text转到SDE Anno FeatureClass

将SDE里的Annotation featureclass到处到 personal geodatabase.

其中,pFC为SDE里要导出的Annotation featureclass, pWSN是Access workspaceName.

 


Public Sub ExportAnno(pFC As IFeatureClass, pFilter As IQueryFilter, pAccessWorkspaceName As IWorkspaceName)
    
    
Dim pWSName As IName
    
Set pWSName = pAccessWorkspaceName  ' QI to IName to open
    
    
Dim pAnnoWS As IFeatureWorkspaceAnno
    
Set pAnnoWS = pWSName.Open
   
    
Dim pWS As IWorkspace
    
Set pWS = pAnnoWS
    
    
' create the feature class description to get the necessary CLSIDs
    Dim pAnnoFCDesc As IFeatureClassDescription
    
Set pAnnoFCDesc = New AnnotationFeatureClassDescription
    
    
' QI to the annotation object class description for another necesasry CLSID
    Dim pAnnoObjClassDesc As IObjectClassDescription
    
Set pAnnoObjClassDesc = pAnnoFCDesc
    
    
    
Dim position As Integer
    position 
= InStr(pFC.AliasName, ".")
                        
    
Dim pFCName As String
    
If position > 0 Then
        pFCName 
= Right(pFC.AliasName, Len(pFC.AliasName) - position)
    
Else
        pFCName 
= pFC.AliasName
    
End If
    
    
'generate fields of new featureclass
    Dim pAllFields As IFields
    
Set pAllFields = New Fields
    
Dim pFieldsEdit As IFieldsEdit
    
Set pFieldsEdit = pAllFields
    
Dim i As Integer
    
For i = 0 To pFC.Fields.FieldCount - 1
     pFieldsEdit.AddField pFC.Fields.Field(i)
    
Next


    
Dim pAnnoClass As IAnnoClass
    
Set pAnnoClass = pFC.Extension
    
    
'get symbolcollection of old featureclass
    Dim pSColl As ISymbolCollection
    
Set pSColl = pAnnoClass.SymbolCollection
    
    
'get reference and scale of old featureclass
    Dim pRefScale As IGraphicsLayerScale
    
Set pRefScale = New GraphicsLayerScale
    pRefScale.Units 
= pAnnoClass.ReferenceScaleUnits
    pRefScale.ReferenceScale 
= pAnnoClass.ReferenceScale
         
    
Dim pAnnoLayerPropsColl As IAnnotateLayerPropertiesCollection
    
Dim pAnnoPropscoll As IAnnotateLayerPropertiesCollection
    
Set pAnnoPropscoll = New AnnotateLayerPropertiesCollection
    
Set pAnnoLayerPropsColl = pAnnoClass.AnnoProperties

    
'get the (first) AnnotateLayerProperties property set in the collection
    Dim pAnnoLayerProps As IAnnotateLayerProperties
    
    
For i = 0 To pAnnoLayerPropsColl.Count - 1
        pAnnoLayerPropsColl.QueryItem i, pAnnoLayerProps, 
NothingNothing
        pAnnoPropscoll.Add pAnnoLayerProps
    
Next
  

    
'create new annotation class
    Dim pNewFC As IFeatureClass
    
Set pNewFC = pAnnoWS.CreateAnnotationClass(pFCName, pAllFields, pAnnoObjClassDesc.InstanceCLSID, _
                                               pAnnoObjClassDesc.ClassExtensionCLSID, pFC.ShapeFieldName, _
                                                
""NothingNothing, pAnnoPropscoll, pRefScale, pSColl, True)
                         
    
Dim pDataset As IDataset
    
Set pDataset = pNewFC
    
    
Dim pTransactions As ITransactions
    
Set pTransactions = pDataset.Workspace
    pTransactions.StartTransaction
    
Const lAutoCommitInterval = 100
    
    
Dim pFDOGLFactory As IFDOGraphicsLayerFactory
    
Set pFDOGLFactory = New FDOGraphicsLayerFactory
    
    
Dim pFDOGLayer As IFDOGraphicsLayer
    
Set pFDOGLayer = pFDOGLFactory.OpenGraphicsLayer(pWS, pNewFC.FeatureDataset, pDataset.Name)
    
    
Dim pTextElement As ITextElement
    
    
Dim lRowCount As Long
    lRowCount 
= 0
    
    
Dim pElementColl As IElementCollection
    
Set pElementColl = New ElementCollection
    pFDOGLayer.BeginAddElements
    
    
    
Dim pfeature As IFeature
    
Dim pFeatureCursor As IFeatureCursor
    
    
Set pFeatureCursor = pFC.Search(pFilter, False)
    
Set pfeature = pFeatureCursor.nextfeature
           
    
Do While Not pfeature Is Nothing
        
Dim pAnnoFea As IAnnotationFeature
        
Set pAnnoFea = pfeature
       
        
Set pTextElement = pAnnoFea.Annotation
    
        pElementColl.Add pTextElement
        
        lRowCount 
= lRowCount + 1
     
        
If lRowCount Mod lAutoCommitInterval = 0 Then
            pFDOGLayer.DoAddElements pElementColl, 
0
            pElementColl.Clear
            pTransactions.CommitTransaction
            pTransactions.StartTransaction
        
End If
    
        
Set pfeature = pFeatureCursor.nextfeature
    
Loop
    
If pElementColl.Count > 0 Then pFDOGLayer.DoAddElements pElementColl, 0
    pElementColl.Clear
    pTransactions.CommitTransaction
    
    
Set pNewFC = Nothing
    pFDOGLayer.EndAddElements
    
Set pFDOGLayer = Nothing
   

    
Set pNewFC = Nothing
  
    
Set pFeatureCursor = Nothing
    
Set pfeature = Nothing
    
Set pAnnoFCDesc = Nothing
    
Set pAnnoObjClassDesc = Nothing
    
Set pAllFields = Nothing
    
Set pFieldsEdit = Nothing
    
Set pAnnoWS = Nothing
    
Set pWSName = Nothing
    
Set pAnnoClass = Nothing
    
Set pRefScale = Nothing
    
Set pAnnoPropscoll = Nothing

End Sub
来自:http://www.cnblogs.com/iswszheng/archive/2009/03/18/1415496.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值