• CAD2GIS:arcengine注记添加


    在做CAD注记转GIS注记,坎坷,百度了几乎所有可能的资料。

    主要参照这里的方法(c++)。我使用C#重写了,均测试通过。

    http://www.cnblogs.com/junyuz/archive/2011/09/01/2162625.html

    重要提示:

           必须创建好注记图层,设置好比例尺和坐标系。困在这里两天没通过。

    方法一 通过IFDOGraphicsLayer添加Elements的方式实现

            
    //Author:AllenRobin http://gisrsman.cnblogs.com
    /// <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;
            }
            //Author:AllenRobin http://gisrsman.cnblogs.com

    junyuz:这两种方法,经过实际测试都可以成功,在导入的时候还需要注意一下空间参考系的问题,需要对应上,特别要注意dwg中的数据是否正确,如果注记的坐标不在参考系范围内,会出现导入失败的现象,我就是因为这个低级的错误,纠结了两天。

    ps. MakeTextElement是创建ITextElement的方法。

    版权声明:本博原创文章可以被转载,但是在未经本人许可前,不得用于任何商业用途或其他以盈利为目的的用途。如需转载,请在转载时声明作者、保留出处。本人保留对本文的一切权利。 作者:AllenRobin Blog:http://gisrsman.cnblogs.com
  • 相关阅读:
    java实现获取当前年月日 小时 分钟 秒 毫秒
    四种常见的 POST 提交数据方式(application/x-www-form-urlencoded,multipart/form-data,application/json,text/xml)
    Cannot send, channel has already failed:
    Java 枚举(enum) 详解7种常见的用法
    C语言指针详解(经典,非常详细)
    ActiveMQ进阶配置
    Frame size of 257 MB larger than max allowed 100 MB
    SpringJMS解析--监听器
    SpringJMS解析-JmsTemplate
    delphi 修改代码补全的快捷键(由Ctrl+Space 改为 Ctrl + alt + Space)
  • 原文地址:https://www.cnblogs.com/GISRSMAN/p/4549444.html
Copyright © 2020-2023  润新知