backup3

        private void changLayoutTemp2(IActiveView activeView, IPageLayout pageLayout, IPageLayout pTempPageLayout)
        {
            IPage pTempPage = pTempPageLayout.Page;

            //set page size and units
            IPage pCurPage = pageLayout.Page;
            pCurPage.Units = pTempPage.Units;
            pCurPage.Orientation = pTempPage.Orientation;

            double dWidth, dHeight;
            pTempPage.QuerySize(out dWidth, out dHeight);
            pCurPage.PutCustomSize(dWidth, dHeight);
            //delet all the element in GraphicsContainer except the MapFrame 
            IGraphicsContainer pGraphicsContainer = activeView.GraphicsContainer;
            IMap pMap = activeView.FocusMap;
            //现有的mxd文档
            IMapFrame pMapFrame = pGraphicsContainer.FindFrame(pMap) as IMapFrame;


            pGraphicsContainer.Reset();
            IElement pElement = pGraphicsContainer.Next();
            while (pElement != null)
            {
                if (pElement is IMapFrame)
                {
                    //模板的
                    IMapFrame pTempMapFrame = (pTempPageLayout as IGraphicsContainer).FindFrame((pTempPageLayout as IActiveView).FocusMap) as IMapFrame;
                    IElement pTempElement = pTempMapFrame as IElement;
                    pElement.Geometry = pTempElement.Geometry;
                    pMapFrame.Border = pTempMapFrame.Border;


                    //方里网
                    IMapGrids pMapGrids = pMapFrame as IMapGrids;
                    pMapGrids.ClearMapGrids();
                    IMapGrids tempGrids = pTempMapFrame as IMapGrids;
                    for (int i = 0; i < tempGrids.MapGridCount; i++)
                    {
                        pMapGrids.AddMapGrid(tempGrids.get_MapGrid(i));
                    }
                }
                //else
                //{
                //    pGraphicsContainer.DeleteElement(pElement);
                //}
                pElement = pGraphicsContainer.Next();
            }
            
            //add element in the template to your cuurent pagelayout
            IGraphicsContainer pTempGraCon = pTempPageLayout as IGraphicsContainer;
            pTempGraCon.Reset();
            pElement = pTempGraCon.Next();
            while (pElement != null)
            {
                if (pElement is IMapFrame)
                {
                    pElement = pTempGraCon.Next();
                    continue;
                }
                else if (pElement is IMapSurroundFrame)
                {
                    IMapSurroundFrame pTempMapSurroundFrame = pElement as IMapSurroundFrame;
                    pTempMapSurroundFrame.MapFrame = pMapFrame;
                    IMapSurround pTempMapSurround = pTempMapSurroundFrame.MapSurround;
                    pMap.AddMapSurround(pTempMapSurround);
                    pGraphicsContainer.AddElement(pTempMapSurroundFrame as IElement, 0);
                }
                else
                {
                    pGraphicsContainer.AddElement(pElement, 0);
                }
                pElement = pTempGraCon.Next();
            }
        }


        /// <summary>
        /// 为PageLayout对象添加经纬网格
        /// </summary>
        /// <param name="pPageLayout"></param>
        /// 
        private void CreateGraticuleMapGrid(IPageLayout pPageLayout)
        {
            //获取MapFrame对象
            IActiveView pAcitiveView = pPageLayout as IActiveView;
            IMap pMap = pAcitiveView.FocusMap;
            IGraphicsContainer pGraphicsContainer = pAcitiveView as IGraphicsContainer;
            IMapFrame pMapFrame = pGraphicsContainer.FindFrame(pMap) as IMapFrame;

            IRgbColor rgbColor = new RgbColor();

            IMapGrids pMapGrids;
            IMapGrid pMapGrid;

            //Create the grid
            pMapGrid = new GraticuleClass();// (IGraticule)pServerContext.CreateObject("esriCarto.Graticule");
            pMapGrid.Name = "Map Grid";

            rgbColor.Red = 166;
            rgbColor.Green = 187;
            rgbColor.Blue = 208;
            IColor color = rgbColor as IColor;

            //Set the line symbol used to draw the grid
            ICartographicLineSymbol pLineSymbol;
            pLineSymbol = new CartographicLineSymbolClass();
            //pLineSymbol = (ICartographicLineSymbol)pServerContext.CreateObject("esriDisplay.CartographicLineSymbol");
            pLineSymbol.Cap = esriLineCapStyle.esriLCSButt;
            pLineSymbol.Width = 1;
            pLineSymbol.Color = color;

            pMapGrid.LineSymbol = pLineSymbol;
            pMapGrid.Border = null; // clear the default border;

            //Set the Tick Properties
            pMapGrid.TickLength = 15;
            pLineSymbol = new CartographicLineSymbolClass();
            //pLineSymbol = (ICartographicLineSymbol)pServerContext.CreateObject("esriDisplay.CartographicLineSymbol");
            pLineSymbol.Cap = esriLineCapStyle.esriLCSButt;
            pLineSymbol.Width = 1;
            pLineSymbol.Color = color;
            pMapGrid.TickLineSymbol = pLineSymbol;
            pMapGrid.TickMarkSymbol = null; //clear the default
            pMapGrid.LabelFormat.Font.Size = 20;

            //Set the Sub Tick Properties
            pMapGrid.SubTickCount = 5;
            pMapGrid.SubTickLength = 10;
            pLineSymbol = new CartographicLineSymbolClass();
            //pLineSymbol = (ICartographicLineSymbol)pServerContext.CreateObject("esriDisplay.CartographicLineSymbol");
            pLineSymbol.Cap = esriLineCapStyle.esriLCSButt;
            pLineSymbol.Width = 0.1;
            pLineSymbol.Color = color;
            pMapGrid.SubTickLineSymbol = pLineSymbol;

            //Marshal.ReleaseComObject(pLineSymbol);

            //Set the Grid labels properties
            IGridLabel pGridLabel;
            pGridLabel = pMapGrid.LabelFormat;
            pGridLabel.LabelOffset = 15;

            stdole.StdFont pFont = new stdole.StdFont();
            pFont.Name = "Arial";
            pFont.Size = 16;

            pMapGrid.LabelFormat.Font = pFont as stdole.IFontDisp;

            //Set the Tick, SubTick, Label Visibility along the 4 sides of the grid
            pMapGrid.SetTickVisibility(true, true, true, true);
            pMapGrid.SetSubTickVisibility(true, true, true, true);
            pMapGrid.SetLabelVisibility(true, true, true, true);

            //Make map grid visible, so it gets drawn when Active View is updated
            pMapGrid.Visible = true;

            //Set the IMeasuredGrid properties
            IMeasuredGrid pMeasuredGrid;
            pMeasuredGrid = pMapGrid as IMeasuredGrid;
            pMeasuredGrid.FixedOrigin = true;
            pMeasuredGrid.XIntervalSize = 0.5; //meridian interval
            pMeasuredGrid.XOrigin = 109; //shift grid 5
            pMeasuredGrid.YIntervalSize = 0.5; //parallel interval
            pMeasuredGrid.YOrigin = 40; //shift grid 5

            // add mapg grid to Layout and refresh
            pMapGrids = pMapFrame as IMapGrids;
            pMapGrids.AddMapGrid(pMapGrid);
        }





            string aaa = @"C:\Users\Administrator\Desktop\bbbbbbb.mxd";
            IMapDocument pMapDocument = new MapDocumentClass();
            pMapDocument.Open(aaa);

            string file = @"C:\Users\Administrator\Desktop\A90_90.mxt";
            IMapDocument pMapDocument2 = new MapDocumentClass();
            pMapDocument2.Open(file);//template's  path

            changLayoutTemp2(pMapDocument.ActiveView, pMapDocument.PageLayout, pMapDocument2.PageLayout);
            pMapDocument.SaveAs("d:\\aa7.mxd", true, true);
change_layout

 

posted on 2016-12-23 14:09 Anders' Yan 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/yansc/p/6214602.html

1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值