CAD Text轉到SDE Anno FeatureClass

將CAD內的Anno Text轉到sde里的Annotation featureclass.對于CAD Text, 它的geometrytype 為Point, 而sde里Annotation featureclass的geometrytype為Polygon,因此IObjectLoader.LoadObjects不適用于轉CAD Text, 只能用IFDOGLFactory.DoAddElements方法.

IFDOGraphicsLayer是專門用于插入annotation feature到geodatabase annotation featureclass的。關于IFDOGraphicsLayer,EDN里有詳細的備注:

 IFDOGraphicsLayer provides a fast mechanism for inserting annotation features into geodatabase annotation feature classes. Adding annotation feature or element should always be done after calling the BeginAddElements method, and after the features or elements are inserted, be sure to issue a call to the EndAddElements method.

If inserting annotation elements without attributes, use the DoAddElements method which takes an enumeration of GraphicElement objects.  If inserting annotation elements with attributes, use the SetupAttributeConversion method to setup the field mapping between the input features and the target annotation feature class, then call DoAddFeature. DoAddFeature will add the element, the placement polygon shape and populate any attributes that are mapped. The SetupAttributeConversion method cannot be called from Visual Basic. Instead, use the SetupAttributeConversion2 method on IFDOAttributeConversion to setup the field mapping. Field mapping should be setup after the BeginAddElements method is called.

ContractedBlock.gif ExpandedBlockStart.gif Code
Private Function InsertNewRecord_CAD(path As String, pSdeFSW As IFeatureWorkspace, target As StringAs Boolean

On Error GoTo err_handle

   
'Source
    Dim pCadWSF As IWorkspaceFactory
    
Set pCadWSF = New CadWorkspaceFactory
    
    
Dim pCadWS As IWorkspace
    
Set pCadWS = pCadWSF.OpenFromFile(GetPathName(path, 0), 0)
    
    
Dim pCadFWS As IFeatureWorkspace
    
Set pCadFWS = pCadWS
    
    
Dim pCadFC As IFeatureClass
     
On Error Resume Next
    
Set pCadFC = pCadFWS.OpenFeatureClass(GetPathName(path, 1& ":Annotation")
   
    
    
If Not pCadFC Is Nothing Then
    
        
Dim pCADFeatureCur As IFeatureCursor
        
Set pCADFeatureCur = pCadFC.Search(NothingFalse)
       
        
Dim pSdeFC As IFeatureClass
        
Set pSdeFC = pSdeFSW.OpenFeatureClass(target)
       
        
Dim pTextSymbol As ITextSymbol
        
Set pTextSymbol = getTextSymbol(pSdeFC)

        
Dim pDataset As IDataset
        
Set pDataset = pSdeFC
 
        
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(pSdeFSW, pSdeFC.FeatureDataset, pDataset.Name)
  
        
Dim pTextElement As ITextElement
  
        
Dim pAnnoText As String
        
Dim pAngle As Double

        
Dim pAnnoTextID As Long
        
Dim pAngleID As Long
        
Dim pTextStringID As Long
        pAnnoTextID 
= pCadFC.Fields.FindField("Text")
        pAngleID 
= pCadFC.Fields.FindField("txtAngle")
        
        
Dim lRowCount As Long
        lRowCount 
= 0
        
        
Dim pElementColl As IElementCollection
        
Set pElementColl = New ElementCollection
        pFDOGLayer.BeginAddElements
       
 
        
Dim pCADFeature As IFeature
        
Set pCADFeature = pCADFeatureCur.NextFeature
       
        
Do While Not pCADFeature Is Nothing
            pAnnoText 
= pCADFeature.Value(pAnnoTextID)
            pAngle 
= pCADFeature.Value(pAngleID)
        
            
Set pTextElement = MakeTextElement(pCADFeature, pAnnoText, pAngle, pTextSymbol)
          
'  pTextElement.Symbol = pTextSymbol
 
            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 pCADFeature = pCADFeatureCur.NextFeature
        
Loop
          
        
Set pSdeFC = Nothing
        
Set pFDOGLayer = Nothing
    
End If

    
Set pCadFC = Nothing
    
Set pCadFWS = Nothing
    
Set pCadWS = Nothing
    
Set pCadWSF = Nothing
    
    InsertNewRecord_CAD 
= True
    
    
Exit Function


err_handle:
    InsertNewRecord_CAD 
= False
    
MsgBox "Error(" & Err.Number & "): " & Err.Description
    utlWriteInfoLog 
"[InsertNewRecord_CAD] error number " & Err.Number & " :" & Err.Description
End Function

 

下面是里面要用到的兩個function

ContractedBlock.gif ExpandedBlockStart.gif Code
Public Function MakeTextElement(pFeature As IFeature, pAnnoText As String, pAngle As Double, pTextSymbol As TextSymbol) As ITextElement
    
    
Dim pPoint As IPoint
    
Set pPoint = New Point
    
Set pPoint = pFeature.Shape
    
    
Dim pTextElement As ITextElement
    
Set pTextElement = New TextElement
    
    pTextElement.Symbol 
= pTextSymbol
    pTextElement.ScaleText 
= True
    pTextElement.Text 
= pAnnoText
    
    
Dim pElement As IElement
    
Set pElement = pTextElement
    pElement.Geometry 
= pPoint
    
    
If pAngle <> 0Then
    
    
Dim pTransform2D As ITransform2D
    
Set pTransform2D = pTextElement
   pTransform2D.Rotate pPoint, (pAngle 
* (PI / 180))
  
'  pTransform2D.Rotate pPoint, pAngle
    End If
    
    
Set MakeTextElement = pTextElement
End Function

 

ContractedBlock.gif ExpandedBlockStart.gif Code
Public Function getTextSymbol(pFeatureClass As IFeatureClass) As ITextSymbol

    
Dim pTextSym As ITextSymbol

    
Dim pAnnoClass As IAnnoClass
    
Set pAnnoClass = pFeatureClass.Extension

    
If Not pAnnoClass.SymbolCollection Is Nothing Then
        
Dim pSColl As ISymbolCollection
        
Set pSColl = pAnnoClass.SymbolCollection
        pSColl.Reset

        
Dim pSymID As ISymbolIdentifier
        
Set pSymID = pSColl.Next
        
Do Until pSymID Is Nothing
            
If TypeOf pSymID.Symbol Is ITextSymbol Then
                
Set pTextSym = pSymID.Symbol
            
End If
            
Set pSymID = pSColl.Next
        
Loop
    
Else

        
Dim pFCur As IFeatureCursor
        
Set pFCur = pFeatureClass.Search(NothingFalse)
        
Dim pAnnofeat As IAnnotationFeature
        
Set pAnnofeat = pFCur.NextFeature
        
Do Until pAnnofeat Is Nothing
            
If TypeOf pAnnofeat.Annotation Is ITextElement Then
                
Set pTextSym = pAnnofeat.Annotation
            
End If
            
Set pAnnofeat = pFCur.NextFeature
        
Loop
    
End If


    
Set getTextSymbol = pTextSym


End Function

 

转载于:https://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、付费专栏及课程。

余额充值