gzstyxb
路人甲
路人甲
  • 注册日期2004-09-22
  • 发帖数358
  • QQ
  • 铜币1045枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1520回复:2

[Arc Engine]怎样写数据到的Annotation Featureclass里面

楼主#
更多 发布于:2005-11-28 09:47
<P>下面是从网上搜寻来的VB代码,与帮助文件里面的VB代码类似。我把它修改成VC代码,却一直无法正确运行。该我代码没有在VB里面试过,但是ArcGis提供的例子却无法正确运行。 那为高人明白请指点一二。</P>
<P>附VB代码:</P>
<P>Public Sub AppendAnnoFeatures(pFeatureClass As IFeatureClass, _<BR> strTextFile As String)</P>
<P> Dim pAnnoClass As IAnnoClass<BR> Set pAnnoClass = pFeatureClass.Extension<BR> If pAnnoClass Is Nothing Then<BR>  MsgBox "Annotation Class not found"<BR>  Exit Sub<BR> End If</P>
<P> '****************<BR> ' 打开文本文件并读取文件<BR> '****************<BR> Dim lFreeFile As Long ' File number<BR> lFreeFile = FreeFile<BR> Open strTextFile For Input As #lFreeFile</P>
<P> Dim sText As String ' Annotation text<BR> Dim dX As Double ' Annotation handle X coordinate<BR> Dim dY As Double ' Annotation handle Y coordinate<BR> Dim dAngle As Double ' Annotation angle in degrees (anticlockwise from due east)<BR> Dim pTextElement As ITextElement</P>
<P> '****************<BR> ' 开始数据库处理事务,并设置为自动提交<BR> '****************<BR> Dim pDataset As IDataset<BR> Dim pTransactions As ITransactions<BR> Set pDataset = pFeatureClass<BR> ' Inline QI to ITransactions<BR> Set pTransactions = pDataset.Workspace<BR> pTransactions.StartTransaction<BR> Const lAutoCommitInterval = 100<BR> <BR> '****************<BR> ' 设置FDOGraphicsLayer - 这是插入annotation的最有效的方法<BR> '****************<BR> Dim pFDOGLFactory As IFDOGraphicsLayerFactory<BR> Set pFDOGLFactory = New FDOGraphicsLayerFactory</P>
<P> Dim pFDOGLayer As IFDOGraphicsLayer<BR> Set pFDOGLayer = pFDOGLFactory.OpenGraphicsLayer(pDataset.Workspace, pFeatureClass.FeatureDataset, pDataset.Name)</P>
<P> Dim pElementColl As IElementCollection<BR> Set pElementColl = New ElementCollection<BR> pFDOGLayer.BeginAddElements</P>
<P> '****************<BR> ' 处理没一行文件数据,直到文件结束<BR> '****************<BR> Dim lRowCount As Long<BR> lRowCount = 0<BR> Do While Not EOF(lFreeFile)<BR>  Input #lFreeFile, sText, dX, dY, dAngle ' Read line of data</P>
<P>  '****************<BR>  ' 创建text element并把它加入到element collection<BR>  '****************<BR>  Set pTextElement = MakeTextElement(sText, dX, dY, dAngle)<BR>  pElementColl.Add pTextElement<BR>  lRowCount = lRowCount + 1</P>
<P>  '****************<BR>  '提交<BR>  '****************<BR>  If lRowCount Mod lAutoCommitInterval = 0 Then<BR>   pFDOGLayer.DoAddElements pElementColl, 0<BR>   pElementColl.Clear<BR>   pTransactions.CommitTransaction<BR>   pTransactions.StartTransaction<BR>  End If</P>
<P> Loop<BR> Close lFreeFile ' 关闭文件.</P>
<P> ' Commit any left over elements<BR> If pElementColl.Count > 0 Then<BR>  pFDOGLayer.DoAddElements pElementColl, 0<BR>  pElementColl.Clear<BR> End If</P>
<P> pFDOGLayer.EndAddElements<BR> pTransactions.CommitTransaction</P>
<P>End Sub</P>
<P>'以下代码是用来创建Text Element<BR>Public Function MakeTextElement(sText As String, _<BR> dX As Double, _<BR> dY As Double, _<BR> dAngle As Double) As ITextElement</P>
<P> ' Create new text element<BR> Dim pTextElement As ITextElement<BR> Set pTextElement = New TextElement<BR> pTextElement.ScaleText = True<BR> pTextElement.Text = sText</P>
<P> ' Set the symbol ID of the element to point to the existing<BR> ' text symbol in the annotation feature class's symbol collection<BR> Dim pGroupSymbolElement As IGroupSymbolElement<BR> Set pGroupSymbolElement = pTextElement<BR> pGroupSymbolElement.SymbolID = 0</P>
<P> ' Set the geometry of the text element<BR> Dim pElement As IElement<BR> Set pElement = pTextElement</P>
<P> Dim pPoint As IPoint<BR> Set pPoint = New Point<BR> pPoint.PutCoords dX, dY<BR> pElement.Geometry = pPoint</P>
<P> ' If Angle is not zero then QI to ITransform2D to rotate the element<BR> If dAngle <> 0# Then<BR>  Const PI = 3.141592657<BR>  Dim pTransform2D As ITransform2D<BR>  Set pTransform2D = pTextElement<BR>  pTransform2D.Rotate pPoint, (dAngle * (PI / 180))<BR> End If<BR> Set MakeTextElement = pTextElement<BR>End Function <BR></P>
喜欢0 评分0
由爱故生忧, 由爱故生怖. 若离于爱者, 无忧亦无怖.
mayiding
路人甲
路人甲
  • 注册日期2004-02-25
  • 发帖数10
  • QQ
  • 铜币142枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2007-04-13 15:57
非常感谢你的代码!
举报 回复(0) 喜欢(0)     评分
whmwxhanshan123
路人甲
路人甲
  • 注册日期2006-06-17
  • 发帖数3108
  • QQ
  • 铜币6445枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2007-04-13 19:29
狂顶<img src="images/post/smile/dvbbs/em01.gif" />
举报 回复(0) 喜欢(0)     评分
游客

返回顶部