Arcgis engine 创建文本标注要素添加到表

方法一:

主要是使用了ISymbolCollectionElement接口设置了Feature的各种属性

IGeometry pointGeometry 这个几何对象应该是一个IPoint;

esriTextHorizontalAlignment 与 esriTextVerticalAlignment指示这个point在Annotation元素(一个面Polygon)的哪个位置,借此确定放置位置。

ISymbolCollectionElement或者IFormattedTextSymbol还有更多的属性可以设置(本文不做补充)

但是此方法没法设置文本标注的旋转角(方法二可以)

public void CreateAnnotationFeature(IGeometry pointGeometry,string text,string fontName,double fontSize,esriTextHorizontalAlignment horizontalAlignment,
        esriTextVerticalAlignment verticalAlignment)
         {
            IFeature feature = featureClass.CreateFeature();
 
            ISymbolCollectionElement symbolCollectionElement = new TextElementClass();
            symbolCollectionElement.FontName = fontName;
            symbolCollectionElement.Size = fontSize;
            symbolCollectionElement.Text = text;
            symbolCollectionElement.HorizontalAlignment = horizontalAlignment;
            symbolCollectionElement.VerticalAlignment = verticalAlignment;                                     
            symbolCollectionElement.Geometry = pointGeometry;

            IElement element = symbolCollectionElement as IElement;
            IAnnotationFeature2 annotationFeature2 = feature as IAnnotationFeature2;
            annotationFeature2.Annotation =element;
            annotationFeature2.Status = esriAnnotationStatus.esriAnnoStatusPlaced;
            feature.Store();
        }

方法二:

主要使用IFormattedTextSymbol接口的方案

这种方法可以设置的参数好像多一些  fmtTextSymb.Angle 这个就是旋转角 传入的参数为角度

private void AddAnno(IFeatureClass featClass, IPoint pt, string textString)
    {
        IFeature feature = featClass.CreateFeature();
        var annoClass = featClass.Extension as IAnnoClass;
        IFontDisp font = new StdFontClass() as IFontDisp;
        font.Name = "Arial";
        font.Bold = true;
        // font.Size = 30;
// load in some reasonable default values..
        IFormattedTextSymbol fmtTextSymb = new TextSymbolClass();
        fmtTextSymb.Font = font;
        fmtTextSymb.Size = 30;
        fmtTextSymb.VerticalAlignment = esriTextVerticalAlignment.esriTVABottom;
        fmtTextSymb.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft;
        fmtTextSymb.Angle = 0;
        fmtTextSymb.CharacterSpacing = 100;
        fmtTextSymb.CharacterWidth = 100;
        fmtTextSymb.FlipAngle = 90;
        fmtTextSymb.Leading = 0;
        fmtTextSymb.WordSpacing = 100;
        fmtTextSymb.Text = textString;  // my special text value..
        ITextElement textElement = new TextElementClass();
        textElement.Symbol = fmtTextSymb;
        textElement.Text = textString;
        IElement element = textElement as IElement;
        element.Geometry = pt;
        (feature as IAnnotationFeature2).Annotation = element;
        feature.Store();
    }
}

参考:https://www.cnblogs.com/yzhyingcool/p/11518652.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值