• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
bobird的学习笔记
博客园    首页    新随笔    联系   管理    订阅  订阅
ArcEngine注记添加
     /// <summary>
        /// 添加到注记图层
        /// </summary>
        /// <param name="pFeatCls">注记图层</param>
        /// <param name="pGeometry">插入的位置:一般是一个IPoint</param>
        /// <returns></returns>
        protected bool InsertAnnoFea(IFeatureClass pFeatCls, IGeometry pGeometry)
        {

            IFeatureClass annocls = pFeatCls;
            IDataset pDataset = annocls as IDataset;
            ITransactions pTransactions = pDataset.Workspace as ITransactions;
            pTransactions.StartTransaction();
            IFDOGraphicsLayerFactory pFDOGLFactory = new FDOGraphicsLayerFactoryClass();
            ILayer tmpLayer = pFDOGLFactory.OpenGraphicsLayer(pDataset.Workspace as IFeatureWorkspace, annocls.FeatureDataset, pDataset.Name);
            IFDOGraphicsLayer pFDOGLayer = tmpLayer as IFDOGraphicsLayer;
            IElementCollection pElementColl = new ElementCollectionClass();

            pFDOGLayer.BeginAddElements();
            ITextElement pTextElement = AnnoUtil.MakeTextElement(text, dHSize, rgbColor, sHFont, dHAngle) as ITextElement;
            IElement pElement = pTextElement as IElement;
            pElement.Geometry = pGeometry;

            pElementColl.Add(pElement, 0);

            pFDOGLayer.DoAddElements(pElementColl, 0);
            pFDOGLayer.EndAddElements();

            pElementColl.Clear();
            pTransactions.CommitTransaction();

            return true;
        }


方法二 通过IAnnotationFeature来实现

     /// <summary>
        /// 添加到注记图层
        /// </summary>
        /// <param name="pFeatCls">注记图层</param>
        /// <param name="pGeometry">插入的位置:一般是一个IPoint</param>
        /// <returns></returns>
        protected bool InsertAnnoFea2(IFeatureClass pFeatCls, IGeometry pGeometry)
        {
            IFeatureClass annocls = pFeatCls;
            IWorkspace workspace = ((IDataset)annocls).Workspace;
            IWorkspaceEdit workspaceEdit = workspace as IWorkspaceEdit;
            bool startEdit = workspaceEdit.IsBeingEdited();
            if (!startEdit)
            {
                workspaceEdit.StartEditing(false);
            }
            workspaceEdit.StartEditOperation();

            ITextElement pTextElement = AnnoUtil.MakeTextElement(text, dHSize, rgbColor, sHFont, dHAngle) as ITextElement;
            IElement pElement = pTextElement as IElement;
            pElement.Geometry = pGeometry;

            IFeature pFeature = annocls.CreateFeature();

            IAnnotationFeature pAnnoFeature = pFeature as IAnnotationFeature;
            pAnnoFeature.Annotation = pElement;
            pFeature.Store();

            workspaceEdit.StopEditOperation();
            workspaceEdit.StopEditing(true);
            return true;
        }
posted on 2016-01-14 15:43  bobird  阅读(1058)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3