人间惊鸿宴

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
  28 随笔 :: 0 文章 :: 17 评论 :: 14509 阅读

①数据源修复

IMapDocument mapDoc = new MapDocumentClass();
mapDoc.Open(mxdPath);
IDataSourceHelperMapDocument helpler = new DataSourceHelperClass();
helpler.FindAndReplaceWorkspaceNamePath(mapDoc, oldpath, mdbPath, true);
//oldpath为打开的mxd模板中加载的层的路径(任意一个)
//mdbPath为新的对应数据的路径

②修改出图过程中的IElement

复制代码
            IMapDocument pDoc = new MapDocumentClass();
            pDoc.Open("D:/Desktop/EXPT.mxd");

            IPageLayout pageLayout = pDoc.PageLayout;
            IGraphicsContainer container = pageLayout as IGraphicsContainer;
            container.Reset();

            IElement ele = null;
            while ((ele=container.Next())!=null)
            {
                IElementProperties eleProp = ele as IElementProperties;

                if (ele is ITextElement)
                {
                    switch (eleProp.Name)
                    {
                        case "TITLE":
                            (ele as ITextElement).Text = "Element_TITLE内容更换测试";
                            break;
                        case "LABEL":
                            (ele as ITextElement).Text = "Element_LABEL内容更换测试";
                            break;
                        case "DATE":
                            (ele as ITextElement).Text = "二零二二年四月";
                            break;
                        default:
                            break;
                    }
                    
                }
                else if (ele is IGraphicElement)
                {

                }
            }
复制代码

③添加辅助图层,并至于对应位置

复制代码
            IMapDocument pDoc = new MapDocumentClass();
            pDoc.Open("D:/Desktop/EXPT.mxd");

            IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace pFW = pWSF.OpenFromFile(@"F:\0505\1矢量数据", 0) as IFeatureWorkspace;
            IFeatureLayer pFLayer = new FeatureLayerClass();
            pFLayer.FeatureClass = pFW.OpenFeatureClass("610330JSYDGZQ");

            pDoc.ActiveView.FocusMap.AddLayer(pFLayer);
            pDoc.ActiveView.FocusMap.MoveLayer(pFLayer, 1);
复制代码

 

posted on   人间惊鸿宴  阅读(51)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示