示例#1
0
        public void ChangelayoutAndSave(string mxdPath, string templatePath, string savePath)
        {
            //   IMapDocument pDoc = new MapDocumentClass();
            IMxdContents pMxdC;
            IMapDocument pMapDocument = new MapDocumentClass();

            pMapDocument.Open(mxdPath, "");
            pMxdC = pMapDocument.PageLayout as IMxdContents;

            IMap        pMap        = pMxdC.ActiveView.FocusMap; //this.axPageLayoutControl1.ActiveView.FocusMap;
            IPageLayout pPageLayout = pMxdC.PageLayout;          //this.axPageLayoutControl1.PageLayout;
            //读取新模板
            IMapDocument pNewDoc = new MapDocumentClass();

            pNewDoc.Open(templatePath, "");
            IMap        pTempMap;
            IPageLayout pTempPagelayout = pNewDoc.PageLayout;

            pTempMap = pNewDoc.get_Map(0);
            IPage pTempPage = pTempPagelayout.Page;

            IPage pCurPage = pPageLayout.Page;

            //替换单位
            pCurPage.Units = pTempPage.Units;
            //exchange page orientation
            pCurPage.Orientation = pTempPage.Orientation;
            //替换页面尺寸
            Double dWidth  = 0;
            Double dHeight = 0;

            pTempPage.QuerySize(out dWidth, out dHeight);
            pCurPage.PutCustomSize(dWidth, dHeight);

            //删除当前Layout中除了mapframe外的所有elements
            IGraphicsContainer pGraphicsCont;
            IElement           pElement;

            pGraphicsCont = pPageLayout as IGraphicsContainer;
            pGraphicsCont.Reset();
            pElement = pGraphicsCont.Next();
            IMapFrame pMapFrame        = null;
            IElement  pMapFrameElement = null;

            while (pElement != null)
            {
                if (pElement is IMapFrame)
                {
                    // Console.WriteLine(pElement.Geometry.GeometryType.ToString() + '0');
                    pMapFrameElement = pElement;
                    pMapFrame        = pElement as IMapFrame;
                    pMapFrame.Border = null;
                }
                else
                {
                    pGraphicsCont.DeleteElement(pElement);
                    pGraphicsCont.Reset();
                }
                pElement = pGraphicsCont.Next();
            }

            //遍历模板的PageLayout中的所有元素,并且替换当前PageLayout中的所有元素
            IGraphicsContainer pTempGraphicsCont;

            pTempGraphicsCont = pTempPagelayout as IGraphicsContainer;
            pTempGraphicsCont.Reset();
            pElement = pTempGraphicsCont.Next();
            IArray pArray;

            pArray = new ESRI.ArcGIS.esriSystem.Array();
            while (pElement != null)
            {
                if (pElement is IMapFrame)
                {
                    pMapFrameElement.Geometry = pElement.Geometry;
                }
                else
                {
                    if (pElement is IMapSurroundFrame)
                    {
                        IMapSurround      pTempMapSurround;
                        IMapSurroundFrame pTempMapSurroundFrame = pElement as IMapSurroundFrame;
                        pTempMapSurroundFrame.MapFrame = pMapFrame;
                        pTempMapSurround = pTempMapSurroundFrame.MapSurround;
                        pMap.AddMapSurround(pTempMapSurround);
                    }

                    pArray.Add(pElement);
                }
                pElement = pTempGraphicsCont.Next();
            }

            int pElementCount = pArray.Count;

            //将模板PageLayout中的其它元素(除了MapFrameElement和MapSurroundFrame外的元素)添加到当前PageLayout中去
            for (int i = 0; i < pElementCount; i++)
            {
                pGraphicsCont.AddElement(pArray.get_Element(pElementCount - 1 - i) as IElement, 0);

                // this.axPageLayoutControl1.ActiveView.Refresh();
            }
            //     pMxdC.ActiveView.Refresh();
            pNewDoc.Close();
            pMapDocument = new MapDocumentClass();
            pMapDocument.New(savePath);
            // IActiveView pActiveView = this.axPageLayoutControl1.ActiveView.FocusMap as IActiveView;
            pMapDocument.ReplaceContents(pMxdC);
            pMapDocument.Save(true, true);
            pMapDocument.Close();
        }
示例#2
0
        public static void ShowAllVertex(IFeatureLayer pFeatLyr)
        {
            m_vertexGeoBag = null;
            if (pFeatLyr == null)
            {
                return;
            }
            IFeatureCursor pFeatureCursor = MapManager.GetSelectedFeatures(pFeatLyr);

            if (pFeatureCursor == null)
            {
                return;
            }
            IFeature pTFeature = null;

            //得到要显示节点的地物
            pTFeature = pFeatureCursor.NextFeature();
            if (pTFeature == null)
            {
                return;
            }
            //只选中一个地物进行节点移动
            m_Map.ClearSelection();
            m_Map.SelectFeature(pFeatLyr as ILayer, pTFeature);
            m_activeView.Refresh();
            //如果为点状地物,不显示节点
            if (pTFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
            {
                return;
            }
            IArray pFeatureArray = null;

            pFeatureArray = new ESRI.ArcGIS.esriSystem.Array();
            pFeatureArray.Add(pTFeature);
            //绘图符号初始化
            SymbolInit();
            IFeature         pFeature = default(IFeature);
            IPointCollection pPointCol = default(IPointCollection);
            IPoint           pPoint = default(IPoint);
            int i = 0; int j = 0;

            m_vertexGeoBag = new GeometryBagClass();
            for (i = 0; i <= pFeatureArray.Count - 1; i++)
            {
                pFeature = pFeatureArray.get_Element(i) as IFeature;
                //获取图形边界的点集
                pPointCol = pFeature.ShapeCopy as IPointCollection;
                for (j = 0; j <= pPointCol.PointCount - 1; j++)
                {
                    pPoint = pPointCol.get_Point(j);
                    if (j == 0 | j == pPointCol.PointCount - 1)
                    {
                        //两个端点的ID设为10
                        pPoint.ID = 10;
                    }
                    else
                    {
                        //中间点的ID设为100
                        pPoint.ID = 100;
                    }
                    IColor pColor = null;
                    object obj    = Type.Missing;
                    //显示节点
                    if (pPoint == pHitPnt)
                    {
                        DisplayGraphic(pPoint, pColor, m_selPointSym as ISymbol);
                    }
                    if (j == 0 || j == pPointCol.PointCount - 1)
                    {
                        DisplayGraphic(pPoint, pColor, m_endPointSym as ISymbol);
                    }
                    else
                    {
                        DisplayGraphic(pPoint, pColor, m_vertexSym as ISymbol);
                    }

                    m_vertexGeoBag.AddGeometry(pPoint, ref obj, ref obj);
                }
            }
        }