private void CopyAndOverwriteMap()
        {
            //Get IObjectCopy interface
            IObjectCopy objectCopy = new ObjectCopyClass();

            //Get IUnknown interface (map to copy)
            object toCopyMap = axPageLayoutControl1.ActiveView.FocusMap;

            //Each Map contained within the PageLayout encapsulated by the
            //PageLayoutControl, resides within a separate MapFrame, and therefore
            //have their IMap::IsFramed property set to True. A Map contained within the
            //MapControl does not reside within a MapFrame. As such before
            //overwriting the MapControl's map, the IMap::IsFramed property must be set
            //to False. Failure to do this will lead to corrupted map documents saved
            //containing the contents of the MapControl.
            IMap map = toCopyMap as IMap;

            map.IsFramed = false;

            //Get IUnknown interface (copied map)
            object copiedMap = objectCopy.Copy(toCopyMap);

            //Get IUnknown interface (map to overwrite)
            object toOverwriteMap = axMapControl1.Map;

            //Overwrite the MapControl's map
            objectCopy.Overwrite(copiedMap, ref toOverwriteMap);

            SetMapExtent();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Save_Click(object sender, EventArgs e)
        {
            try
            {
                //空白文档不保存
                if (String.IsNullOrEmpty(m_mapControl.DocumentFilename))
                {
                    return;
                }

                //创建地图文档,调用open方法,调用ReplaceContents方法
                IMapDocument mapDocument = new MapDocumentClass();
                mapDocument.Open(m_mapControl.DocumentFilename);
                mapDocument.ReplaceContents(m_mapControl as IMxdContents);

                IObjectCopy objCopy = new ObjectCopyClass(); //使用Copy,避免共享引用
                m_mapControl.Map = (IMap)objCopy.Copy(mapDocument.get_Map(0));
                objCopy          = null;

                mapDocument.Save(mapDocument.UsesRelativePaths, false);
                mapDocument.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("请联系管理员,错误原因是:" + ex.Message);
            }
        }
Ejemplo n.º 3
0
        private void CopyAndOverwriteMap(MainForm mForm)
        {
            try
            {
                //Get IObjectCopy interface
                IObjectCopy objectCopy = new ObjectCopyClass();

                //Get IUnknown interface (map to copy)
                object toCopyMap = mForm.axMapControl1.ActiveView.FocusMap;

                //Get IUnknown interface (copied map)
                object copiedMap = objectCopy.Copy(toCopyMap);

                //Get IUnknown interface (map to overwrite)
                object toOverwriteMap = axPageLayoutControl1.ActiveView.FocusMap;

                //Overwrite the MapControl's map
                objectCopy.Overwrite(copiedMap, ref toOverwriteMap);
            }
            catch (Exception ex)
            {
                frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog();
                return;
            }
        }
Ejemplo n.º 4
0
        public void Apply()
        {
            IObjectCopy             copy     = new ObjectCopyClass();
            IRepresentationRenderer renderer = copy.Copy(this.irepresentationRenderer_0) as IRepresentationRenderer;

            this.igeoFeatureLayer_0.Renderer = renderer as IFeatureRenderer;
        }
Ejemplo n.º 5
0
 public void SyncMapObject(IMap pSourceMap, ref IMap pTargetMap, bool bClearElements)
 {
     try
     {
         if ((pSourceMap != null) && (pTargetMap != null))
         {
             IObjectCopy copy = null;
             copy = new ObjectCopyClass();
             object pInObject = null;
             pInObject = pSourceMap;
             object obj3 = null;
             obj3 = copy.Copy(pInObject);
             object pOverwriteObject = null;
             pOverwriteObject = pTargetMap;
             copy.Overwrite(obj3, ref pOverwriteObject);
             IActiveView        view = pTargetMap as IActiveView;
             IGraphicsContainer graphicsContainer = view.GraphicsContainer;
             if (graphicsContainer != null)
             {
                 IViewManager manager          = view as IViewManager;
                 ISelection   elementSelection = manager.ElementSelection;
                 view.Selection = elementSelection;
             }
             if (bClearElements)
             {
                 graphicsContainer.DeleteAllElements();
             }
         }
     }
     catch (Exception exception)
     {
         this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.CoreFun", "SyncMapObject", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
     }
 }
Ejemplo n.º 6
0
 private void method_2()
 {
     if (this.igeoFeatureLayer_0 == null)
     {
         this.idotDensityRenderer_0 = null;
     }
     else
     {
         IDotDensityRenderer pInObject = this.igeoFeatureLayer_0.Renderer as IDotDensityRenderer;
         if (pInObject == null)
         {
             if (this.idotDensityRenderer_0 == null)
             {
                 this.idotDensityRenderer_0 = new DotDensityRendererClass();
                 this.idotDensityRenderer_0.DotDensitySymbol = this.CreateDotDensityFillSymbol();
                 this.idotDensityRenderer_0.DotValue         = 0.0;
             }
         }
         else
         {
             IObjectCopy copy = new ObjectCopyClass();
             this.idotDensityRenderer_0 = copy.Copy(pInObject) as IDotDensityRenderer;
         }
     }
 }
Ejemplo n.º 7
0
        public void Apply()
        {
            IObjectCopy          copy     = new ObjectCopyClass();
            IClassBreaksRenderer renderer = copy.Copy(this.iclassBreaksRenderer_0) as IClassBreaksRenderer;

            this.igeoFeatureLayer_0.Renderer = renderer as IFeatureRenderer;
        }
Ejemplo n.º 8
0
        public static void CopyAndOverwriteMap(AxMapControl axMapControl, AxPageLayoutControl axPageLayoutControl)
        {
            IObjectCopy objectCopy   = new ObjectCopyClass();
            object      toCopyMap    = axMapControl.Map;
            object      copiedMap    = objectCopy.Copy(toCopyMap);
            IPageLayout pagelayout   = axPageLayoutControl.PageLayout;
            object      overwriteMap = (pagelayout as IActiveView).FocusMap;

            objectCopy.Overwrite(toCopyMap, ref overwriteMap);
            IGraphicsContainer pGraphicsContainer = pagelayout as IGraphicsContainer;
            IMapFrame          pMapFrame          = (IMapFrame)pGraphicsContainer.FindFrame(overwriteMap);
            IElement           pElement           = pMapFrame as IElement;
            IEnumElement       pEnumElement       = pGraphicsContainer.LocateElementsByEnvelope(pElement.Geometry.Envelope);
            IElement           pElementIcon       = pEnumElement.Next();

            while (pElementIcon != null)
            {
                if (pElementIcon is IMapSurroundFrame)
                {
                    if ((pElementIcon as IMapSurroundFrame).MapSurround is IScaleBar)
                    {
                        (pElementIcon as IMapSurroundFrame).MapFrame = pMapFrame;
                    }
                }
                pElementIcon = pEnumElement.Next();
            }
            axPageLayoutControl.ActiveView.Refresh();
        }
Ejemplo n.º 9
0
        //added by chulili 20110730 根据nodeKey查找图层,
        //yjl20110930 modify 返回一个图层拷贝
        public static ILayer GetLayerByNodeKey(IMap pMap, string strNodeKey)
        {
            if (pMap == null)
            {
                return(null);
            }
            if (strNodeKey.Equals(string.Empty))
            {
                return(null);
            }

            ILayer pSearchLayer = null;

            //循环子节点,比对NodeKey
            for (int i = 0; i < pMap.LayerCount; i++)
            {
                ILayer pLayer = pMap.get_Layer(i);
                if (pLayer != null)
                {   //调用查找图层的函数
                    pSearchLayer = GetLayerByNodeKey(pMap, pLayer, strNodeKey);
                    if (pSearchLayer != null)
                    {
                        IObjectCopy pOC      = new ObjectCopyClass();
                        ILayer      tmpLayer = pOC.Copy(pSearchLayer) as ILayer;
                        return(tmpLayer);
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 实现ESRI的对象复制方法
        /// </summary>
        /// <param name="pInObject">原始对象</param>
        /// <param name="pOverwriteObject">复制后的对象</param>
        public static void ObjectCopy(object pInObject, ref object pOverwriteObject)
        {
            IObjectCopy objectCopy = new ObjectCopyClass();
            object      copyedObj  = objectCopy.Copy(pInObject);

            objectCopy.Overwrite(copyedObj, ref pOverwriteObject);
        }
Ejemplo n.º 11
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (cBoxZT.Text == "")
            {
                return;
            }
            bool isSpecial = ModGetData.IsMapSpecial();

            if (isSpecial) //如果找特定专题
            {
                DesMap = new MapClass();
                ModGetData.AddMapOfNoneXZQ(DesMap, "DOM", cBoxZT.Text, SourceMap);
                if (DesMap.LayerCount == 0)
                {
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "未找到图层。");
                    this.DialogResult = DialogResult.Cancel;
                }
                ModuleMap.LayersComposeEx(DesMap); //图层排序
            }
            else
            {
                IObjectCopy pOC = new ObjectCopyClass();
                DesMap = pOC.Copy(SourceMap) as IMap; //复制地图
            }
            this.DialogResult = DialogResult.OK;
        }
Ejemplo n.º 12
0
 public void SyncPageLayoutObject(IPageLayout pSourcePage, ref IPageLayout pTargetPage)
 {
     try
     {
         if ((pSourcePage != null) && (pTargetPage != null))
         {
             IObjectCopy copy = null;
             copy = new ObjectCopyClass();
             object pInObject = null;
             pInObject = pSourcePage;
             object obj3 = null;
             obj3 = copy.Copy(pInObject);
             object pOverwriteObject = null;
             pOverwriteObject = pTargetPage;
             copy.Overwrite(obj3, ref pOverwriteObject);
             IActiveView view = pTargetPage as IActiveView;
             if (view.GraphicsContainer != null)
             {
                 IViewManager manager          = view as IViewManager;
                 ISelection   elementSelection = manager.ElementSelection;
                 view.Selection = elementSelection;
             }
         }
     }
     catch (Exception exception)
     {
         this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.CoreFun", "SyncPageLayoutObject", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
     }
 }
Ejemplo n.º 13
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (cBoxScale.Text == "" || cBoxZT.Text == "")
            {
                return;
            }
            if (this.WriteLog)
            {
                Plugin.LogTable.Writelog("选择比例尺为:" + cBoxScale.Text + ",专题为:" + cBoxZT.Text);
            }
            //DevComponents.Editors.ComboItem dataItem = cBoxZT.SelectedItem as DevComponents.Editors.ComboItem;
            //DevComponents.AdvTree.Node dataNode = dataItem.Tag as DevComponents.AdvTree.Node;
            bool isSpecial = ModGetData.IsMapSpecial();

            if (isSpecial)
            {
                pMap = new MapClass();
                ModGetData.AddMapOfByXZQ(pMap, "TDLY", cBoxZT.Text, pAxMapControl.Map, xzq_xianMC);

                ModuleMap.LayersComposeEx(pMap);//图层排序
            }
            else
            {
                IObjectCopy pOC = new ObjectCopyClass();
                pMap = pOC.Copy(pAxMapControl.Map) as IMap;//复制地图
            }
            this.DialogResult = DialogResult.OK;
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 主地图控件中的地图复制到布局控件中
        /// </summary>
        private void CopyMapToPageLayout()
        {
            object      copyFromMap = axMapControlMainMap.Map;
            object      copyToMap   = axPageLayoutControl.ActiveView.FocusMap;
            IObjectCopy pObjectCopy = new ObjectCopyClass();

            pObjectCopy.Overwrite(pObjectCopy.Copy(copyFromMap), copyToMap);
        }
Ejemplo n.º 15
0
 public void CopyAndOverwriteMap(AxMapControl mapcontrol, AxPageLayoutControl PageLayoutControl)
 {
     IObjectCopy objectCopy = new ObjectCopyClass();
     object toCopyMap = mapcontrol.Map;
     object copiedMap = objectCopy.Copy(toCopyMap);
     object toOverwriteMap = PageLayoutControl.ActiveView.FocusMap;
     objectCopy.Overwrite(copiedMap, ref toOverwriteMap);
 }
Ejemplo n.º 16
0
 public void mapConnectPage()
 {
     IObjectCopy objectCopy = new ObjectCopyClass();
     object toCopyMap = mapcontrol.Map;
     object copiedMap = objectCopy.Copy(toCopyMap);
     object toOverwriteMap = this.axPageLayoutControl1.ActiveView.FocusMap;
     objectCopy.Overwrite(copiedMap, ref toOverwriteMap);
 }
Ejemplo n.º 17
0
        public void Apply()
        {
            IObjectCopy         copy     = new ObjectCopyClass();
            IDotDensityRenderer renderer = copy.Copy(this.idotDensityRenderer_0) as IDotDensityRenderer;

            renderer.CreateLegend();
            this.igeoFeatureLayer_0.Renderer = renderer as IFeatureRenderer;
        }
Ejemplo n.º 18
0
            internal TinRenderWrap(ITinRenderer itinRenderer_2, bool bool_1)
            {
                this.itinRenderer_1 = itinRenderer_2;
                IObjectCopy copy = new ObjectCopyClass();

                this.itinRenderer_0 = copy.Copy(this.itinRenderer_1) as ITinRenderer;
                this.bool_0         = bool_1;
            }
Ejemplo n.º 19
0
        /// <summary>
        /// 实现MapControl与Pagelayout的同步方法
        /// </summary>
        private void synchronization()
        {
            IObjectCopy objectCopy  = new ObjectCopyClass();
            object      copyFromMap = axMapControl1.Map;
            object      copyMap     = objectCopy.Copy(copyFromMap);
            object      copyToMap   = axPageLayoutControl1.ActiveView.FocusMap;

            objectCopy.Overwrite(copyMap, ref copyToMap);
        }
Ejemplo n.º 20
0
            public static void CopyAndOverwriteMap(AxMapControl axMapControl, AxPageLayoutControl axPageLayoutControl)
            {
                IObjectCopy objectCopy   = new ObjectCopyClass();
                object      toCopyMap    = axMapControl.Map;
                object      copiedMap    = objectCopy.Copy(toCopyMap);
                object      overwriteMap = axPageLayoutControl.ActiveView.FocusMap;

                objectCopy.Overwrite(toCopyMap, ref overwriteMap);
            }
Ejemplo n.º 21
0
        public void mapConnectPage()
        {
            IObjectCopy objectCopy     = new ObjectCopyClass();
            object      toCopyMap      = mapcontrol.Map;
            object      copiedMap      = objectCopy.Copy(toCopyMap);
            object      toOverwriteMap = this.axPageLayoutControl1.ActiveView.FocusMap;

            objectCopy.Overwrite(copiedMap, ref toOverwriteMap);
        }
Ejemplo n.º 22
0
        public static void CopyMap(IMap fromMap, IMap toMap)
        {
            IObjectCopy objectCopy  = new ObjectCopyClass();
            object      copyFromMap = fromMap;
            object      copyMap     = objectCopy.Copy(copyFromMap);
            object      copyToMap   = toMap;

            objectCopy.Overwrite(copyMap, ref copyToMap);
        }
Ejemplo n.º 23
0
 public static void CopyAndOverwriteMap(AxMapControl map, AxPageLayoutControl page)
 {
     //获取拷贝接口对象
     IObjectCopy objectCopy = new ObjectCopyClass();
     object toCopyMap = map.Map;
     object copiedMap = objectCopy.Copy(toCopyMap);//复制地图到copiedMap
     object toOverWriteMap = page.ActiveView.FocusMap;//获取视图控件的焦点地图
     objectCopy.Overwrite(copiedMap, ref toOverWriteMap);//复制地图
 }
Ejemplo n.º 24
0
        public void Apply()
        {
            IObjectCopy copy = new ObjectCopyClass();
            IProportionalSymbolRenderer renderer =
                copy.Copy(this.iproportionalSymbolRenderer_0) as IProportionalSymbolRenderer;

            renderer.CreateLegendSymbols();
            this.igeoFeatureLayer_0.Renderer = renderer as IFeatureRenderer;
        }
Ejemplo n.º 25
0
        public void Apply()
        {
            this.isimpleRenderer_0.Label       = this.txtLabel.Text;
            this.isimpleRenderer_0.Description = this.txtDescription.Text;
            IObjectCopy     copy     = new ObjectCopyClass();
            ISimpleRenderer renderer = copy.Copy(this.isimpleRenderer_0) as ISimpleRenderer;

            this.igeoFeatureLayer_0.Renderer = renderer as IFeatureRenderer;
        }
Ejemplo n.º 26
0
        public void CopyAndOverwriteMap(AxMapControl mapcontrol, AxPageLayoutControl PageLayoutControl)
        {
            IObjectCopy objectCopy     = new ObjectCopyClass();
            object      toCopyMap      = mapcontrol.Map;
            object      copiedMap      = objectCopy.Copy(toCopyMap);
            object      toOverwriteMap = PageLayoutControl.ActiveView.FocusMap;

            objectCopy.Overwrite(copiedMap, ref toOverwriteMap);
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Copy and overwrite map in eagle eye.
        /// </summary>
        /// <param name="mapControl1">main map control.</param>
        /// <param name="mapControl2">eagleEye map control2.</param>
        public static void CopyAndOverwriteMap(IMapControl4 mapControl1, IMapControl4 mapControl2)
        {
            IObjectCopy objectCopy = new ObjectCopyClass();
            object      focusMap   = mapControl1.ActiveView.FocusMap;
            object      pInObject  = objectCopy.Copy(focusMap);
            object      focusMap2  = mapControl2.ActiveView.FocusMap;

            objectCopy.Overwrite(pInObject, ref focusMap2);
        }
Ejemplo n.º 28
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="EntranceSymbol">符号对象</param>
        /// <param name="SymbologyStyleClass">符号样式类</param>
        public FormSymbolSelector(ISymbol EntranceSymbol, esriSymbologyStyleClass SymbologyStyleClass)
        {
            InitializeComponent();
            IObjectCopy pObjectCopy = new ObjectCopyClass();

            InSymbol = pObjectCopy.Copy(EntranceSymbol) as ISymbol;
            CurrentSymbologyStyleClass = SymbologyStyleClass;
            currentStyleGalleryItem    = new ServerStyleGalleryItemClass();
            pOutlineSymbol             = new SimpleLineSymbolClass();
        }
Ejemplo n.º 29
0
        /// <summary>
        /// 将MainMapControl数据复制到PageLayout
        /// </summary>
        private void CopyToPageLayout()
        {
            IObjectCopy pObjectCopy = new ObjectCopyClass();
            object      copyFromMap = MainMapControl.Map;
            object      copiedMap   = pObjectCopy.Copy(copyFromMap);//复制地图到copiedMap中
            object      copyToMap   = MainPageLayoutControl.ActiveView.FocusMap;

            pObjectCopy.Overwrite(copiedMap, ref copyToMap); //复制地图
            MainPageLayoutControl.ActiveView.Refresh();
        }
Ejemplo n.º 30
0
        private void CopyToPageLayout()
        {
            IObjectCopy pObjectCopy = new ObjectCopyClass();
            object      copyFromMap = axMapControl1.Map;
            object      copiedmap   = pObjectCopy.Copy(copyFromMap);//复制地图到copiedmap
            object      copytomap   = axPageLayoutControl1.ActiveView.FocusMap;

            pObjectCopy.Overwrite(copiedmap, ref copytomap);//复制地图
            axPageLayoutControl1.ActiveView.Refresh();
        }
Ejemplo n.º 31
0
        public static void CopyAndOverwriteMap(AxMapControl map, AxPageLayoutControl page)
        {
            //获取拷贝接口对象
            IObjectCopy objectCopy     = new ObjectCopyClass();
            object      toCopyMap      = map.Map;
            object      copiedMap      = objectCopy.Copy(toCopyMap); //复制地图到copiedMap
            object      toOverWriteMap = page.ActiveView.FocusMap;   //获取视图控件的焦点地图

            objectCopy.Overwrite(copiedMap, ref toOverWriteMap);     //复制地图
        }
Ejemplo n.º 32
0
        public void CopyAndWriteMap()
        {
            IObjectCopy objectCopy     = new ObjectCopyClass();
            object      toCopyMap      = axMapControl1.Map;
            object      copiedMap      = objectCopy.Copy(toCopyMap);// 把axMapControl1.Map定义为toCopyMap,然后复制到copiedMap中
            object      toOverwriteMap = axPageLayoutControl1.ActiveView.FocusMap;

            objectCopy.Overwrite(copiedMap, ref toOverwriteMap);
            axPageLayoutControl1.ActiveView.Refresh();
        }
Ejemplo n.º 33
0
//        同步 数据视图、布局视图

        private void axMapControl1_OnExtentUpdated(Object sender, IMapControlEvents2_OnExtentUpdatedEvent e)
        {
            IObjectCopy pobjectcopy = new ObjectCopyClass();
            object      from        = pobjectcopy.Copy(axMapControl1.Map);
            object      to          = axPageLayoutControl1.ActiveView.FocusMap;

            pobjectcopy.Overwrite(from, ref to);

            axPageLayoutControl1.ActiveView.Refresh();
        }
        public static ILayer Clone(this ILayer layer)
        {
            if (layer is IPersistStream) {
                IObjectCopy objectCopy = new ObjectCopyClass();
                object clone = objectCopy.Copy(layer);
                ILayer layerClone = clone as ILayer;
                return layerClone;
            }
            if (layer is IPersistVariant) {
                // Create an XML Stream
                IXMLStream xmlStream = new XMLStreamClass();
                IVariantStreamIO variantStreamIO = new VariantStreamIOClass() {
                    Stream = (IStream)xmlStream
                };

                // Save Layer to Stream
                IVariantStream variantStream = (IVariantStream)variantStreamIO;
                IPersistVariant save = (IPersistVariant)layer;
                save.Save(variantStream);

                // Move Seek Pointer to beginning of Stream
                xmlStream.Reset();

                // Create New Layer
                ILayer newlayer = null;
                if (layer is IImageServerLayer) {
                    newlayer = new ImageServerLayerClass();
                }
                if (newlayer == null) { return null; }

                // Create new Layer
                IPersistVariant load = (IPersistVariant)newlayer;
                load.Load(variantStream);

                // Return Cloned Layer
                return newlayer;
            }
            return null;
        }
Ejemplo n.º 35
0
 public void copyToPageLayout()
 {
     IObjectCopy objectcopy = new ObjectCopyClass();
     object copyFromMap = Global.mainmap.Map;
     object copyMap = objectcopy.Copy(copyFromMap);
     object copyToMap = Global.plt.ActiveView.FocusMap;
     objectcopy.Overwrite(copyMap, ref copyToMap);
 }
    public IClone Clone()
    {
      //ClonableObjClass obj = new ClonableObjClass();
      //obj.Assign(this);

      //use the C++ way to clone the object. Write it into a memory stream
      IObjectCopy objectCopy = new ObjectCopyClass();
      object obj = objectCopy.Copy((object)this);

      return (IClone)obj;
    }
Ejemplo n.º 37
0
        private void GeneratePageLayout()
        {
            IPageLayout pageLayout = axPageLayoutControl1.PageLayout;
            IGraphicsContainer pGraphicsContainer = pageLayout as IGraphicsContainer;
            pGraphicsContainer.DeleteAllElements();
            IPage pPage = new PageClass();
            pPage = pageLayout.Page;
            pPage.PutCustomSize(36, 24);
            IActiveView pActiveView = pageLayout as IActiveView;
            IMap pMap = pActiveView.FocusMap;

            IMapFrame mapFrame1 = pGraphicsContainer.FindFrame(pMap) as IMapFrame;
            IEnvelope pEnvelope = new EnvelopeClass();
            pEnvelope.PutCoords(1.5, 3, 17.5, 20);
            IElement pElement = mapFrame1 as IElement;
            pElement.Geometry = pEnvelope;

            //Map frame 2
            IMap mapDF1 = new MapClass();

            IMapFrame mapFrame2 = new MapFrameClass();

            mapFrame2.Map = mapDF1;
            IElement element1 = mapFrame2 as IElement;
            IEnvelope envelope1 = new EnvelopeClass();
            envelope1.PutCoords(18.5, 3, 34.5, 20);
            element1.Geometry = envelope1;
            //?????element 1 or bot map always hide???

            pGraphicsContainer.AddElement(element1, 0);
            //#
            //////add map---problem shot
            //mapFrame1.Map = m_MapControltop.ActiveView.FocusMap;
            //mapFrame2.Map = m_MapControlbase.ActiveView.FocusMap;
            //#
            //TRY to use ObjectCopy
            //copy map to top mapframe of pagelayoutcontrol
            IObjectCopy objectCopy1 = new ObjectCopyClass();
            object toCopyMap1 = m_MapControltop.ActiveView.FocusMap;
            //IMap map1 = toCopyMap1 as IMap;
            //map1.IsFramed = true;
            object copiedMap1 = objectCopy1.Copy(toCopyMap1);
            object toOverwriteMap1 = mapFrame1.Map;
            objectCopy1.Overwrite(copiedMap1, ref toOverwriteMap1);
            //SetMapExtent1();
            //copy map to bot mapframe of pagelayoutcontrol
            IObjectCopy objectCopy2 = new ObjectCopyClass();
            object toCopyMap2 = m_MapControlbase.ActiveView.FocusMap;
            object copiedMap2 = objectCopy2.Copy(toCopyMap2);
            object toOverwriteMap2 = mapFrame2.Map;
            objectCopy2.Overwrite(copiedMap2, ref toOverwriteMap2);
            mapFrame1.Map.Name = "MapTop";
            mapFrame2.Map.Name = "MapBot";
            //try to change scale

            IGraphicsContainer container = this.axPageLayoutControl1.GraphicsContainer;
            container.Reset();
            IElement element = container.Next();
            int index = 0;
            while (element != null)
            {
                if (element is IMapFrame)
                {
                    IMapFrame mapFrame = (IMapFrame)element;
                    string sMapName = mapFrame.Map.Name;
                    IElementProperties elementProperties = (IElementProperties)element;
                    string slementName = elementProperties.Name;
                    index += 1;
                }
                element = container.Next();
            }

            //add title
            ITextElement teTitle = new TextElementClass();
            IPoint ptTitle = new PointClass();
            ptTitle.PutCoords(18, 22.5);
            IElement eleTitle = teTitle as IElement;
            eleTitle = MakeATextElement(ptTitle, tbStNum.Text + " " + tbStNa.Text + " Historical Aerial Comparison", 80);
            pGraphicsContainer.AddElement(eleTitle, 0);

            string topYear = cboTopYear.Text;
            string botYear = cboBotYear.Text;
            //Add subtitle
            ITextElement teSubTitle1 = new TextElementClass();
            IPoint ptSubTitle1 = new PointClass();
            ptSubTitle1.PutCoords(9.5, 21);
            IElement eleSubTitle1 = teSubTitle1 as IElement;
            eleSubTitle1 = MakeATextElement(ptSubTitle1, topYear, 45);
            pGraphicsContainer.AddElement(eleSubTitle1, 0);
            //Add Subtitle2
            ITextElement teSubTitle2 = new TextElementClass();
            IPoint ptSubTitle2 = new PointClass();
            ptSubTitle2.PutCoords(26.5, 21);
            IElement eleSubTitle2 = teSubTitle2 as IElement;
            eleSubTitle2 = MakeATextElement(ptSubTitle2, botYear, 45);
            pGraphicsContainer.AddElement(eleSubTitle2, 0);

            //Add Scale Bar
            AddScaleBar(mapFrame1.Map);
            //Add North Arrow
            AddNorthArrow(axPageLayoutControl1.PageLayout, mapFrame1.Map);
            axPageLayoutControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
            MessageBox.Show("Done!");
        }
Ejemplo n.º 38
0
 private void Copy(int sourceLayerIndex, IEnumerable<int> targetLayerIndices)
 {
     var sourceLayer = _rasterLayers[sourceLayerIndex].Layer as IRasterLayer;
     //Debug.Assert(sourceLayer != null, "Source layer not found");
     if (sourceLayer != null)
     {
         IObjectCopy objectCopier = new ObjectCopyClass();
         IRasterRenderer sourceRender = sourceLayer.Renderer;
         //Debug.Assert(sourceRender != null, "Source layer has no renderer");
         if (sourceRender != null)
         {
             foreach (int index in targetLayerIndices)
             {
                 var destLayer = _rasterLayers[index].Layer as IRasterLayer;
                 //Debug.Assert(destLayer != null, "Destination layer not found");
                 if (destLayer != null)
                     //destLayer.Renderer = sourceRender;  //layers share the same renderer
                     destLayer.Renderer = (IRasterRenderer)objectCopier.Copy(sourceRender);
             }
         }
     }
     ArcMap.Document.UpdateContents();
     ArcMap.Document.ActiveView.Refresh();
 }
Ejemplo n.º 39
0
        private static double GetProjectedLength(IPolyline line)
        {
            var copy = new ObjectCopyClass();
            var l2 = copy.Copy(line) as IPolyline;

            var factory = new SpatialReferenceEnvironmentClass();
            var fromSR = factory.CreateGeographicCoordinateSystem((int)esriSRGeoCS3Type.esriSRGeoCS_Xian1980);//西安80
            var toSR = factory.CreateProjectedCoordinateSystem((int)esriSRProjCS4Type.esriSRProjCS_Xian1980_3_Degree_GK_Zone_40);//西安80
            l2.SpatialReference = fromSR;
            l2.Project(toSR);
            return l2.Length;
        }
Ejemplo n.º 40
0
        private void axMapControl1_OnAfterScreenDraw(object sender, IMapControlEvents2_OnAfterScreenDrawEvent e)
        {
            IObjectCopy pOCopy = new ObjectCopyClass();
            System.Object pToCopyMap = axMapControl1.Map;
            System.Object pCopiedMap = pOCopy.Copy(pToCopyMap);
            System.Object pToOverMap = axPageLayoutControl1.ActiveView.FocusMap;

            pOCopy.Overwrite(pCopiedMap, ref pToOverMap);
            axPageLayoutControl1.ActiveView.Refresh();
        }
    public void Assign(IClone src)
    {

      //1. make sure that src is pointing to a valid object
      if (null == src)
      {
        throw new COMException("Invalid object.");
      }

      //2. make sure that the type of src is of type 'TriangleElementClass'
      if (!(src is TriangleElementClass))
      {
        throw new COMException("Bad object type.");
      }

      //3. assign the properties of src to the current instance
      TriangleElementClass srcTriangle = (TriangleElementClass)src;
      m_elementName = srcTriangle.Name;
      m_elementType = srcTriangle.Type;
      m_autoTrans = srcTriangle.AutoTransform;
      m_scaleRef = srcTriangle.ReferenceScale;
      m_rotation = srcTriangle.Angle;
      m_size = srcTriangle.Size;
      m_anchorPointType = srcTriangle.AnchorPoint;

      IObjectCopy objCopy = new ObjectCopyClass();

      //take care of the custom property
      if (null != srcTriangle.CustomProperty)
      {
        if (srcTriangle.CustomProperty is IClone)
          m_customProperty = (object)((IClone)srcTriangle.CustomProperty).Clone();
        else if (srcTriangle.CustomProperty is IPersistStream)
        {
          m_customProperty = objCopy.Copy((object)srcTriangle.CustomProperty);
        }
        else if (srcTriangle.CustomProperty.GetType().IsSerializable)
        {
          //serialize to a memory stream
          MemoryStream memoryStream = new MemoryStream();
          BinaryFormatter binaryFormatter = new BinaryFormatter();
          binaryFormatter.Serialize(memoryStream, srcTriangle.CustomProperty);
          byte[] bytes = memoryStream.ToArray();

          memoryStream = new MemoryStream(bytes);
          m_customProperty = binaryFormatter.Deserialize(memoryStream);
        }
      }

      if (null != srcTriangle.SpatialReference)
        m_nativeSR = objCopy.Copy(srcTriangle.SpatialReference) as ISpatialReference;
      else
        m_nativeSR = null;

      if (null != srcTriangle.FillSymbol)
      {
        m_fillSymbol = objCopy.Copy(srcTriangle.FillSymbol) as ISimpleFillSymbol;
      }
      else
        m_fillSymbol = null;

      if (null != srcTriangle.Geometry)
      {
        m_triangle = objCopy.Copy(srcTriangle.Geometry) as IPolygon;
        m_pointGeometry = objCopy.Copy(((IArea)m_triangle).Centroid) as IPoint;
      }
      else
      {
        m_triangle = null;
        m_pointGeometry = null;
      }
    }
		private void CopyAndOverwriteMap()
		{
			//Get IObjectCopy interface
			IObjectCopy objectCopy = new ObjectCopyClass(); 

			//Get IUnknown interface (map to copy)
			object toCopyMap = axPageLayoutControl1.ActiveView.FocusMap;

            //Each Map contained within the PageLayout encapsulated by the 
            //PageLayoutControl, resides within a separate MapFrame, and therefore 
            //have their IMap::IsFramed property set to True. A Map contained within the 
            //MapControl does not reside within a MapFrame. As such before 
            //overwriting the MapControl's map, the IMap::IsFramed property must be set 
            //to False. Failure to do this will lead to corrupted map documents saved 
            //containing the contents of the MapControl.
            IMap map = toCopyMap as IMap;
            map.IsFramed = false;

			//Get IUnknown interface (copied map)
			object copiedMap = objectCopy.Copy(toCopyMap);

			//Get IUnknown interface (map to overwrite)
			object toOverwriteMap = axMapControl1.Map;

			//Overwrite the MapControl's map
			objectCopy.Overwrite(copiedMap, ref toOverwriteMap);

			SetMapExtent();
		}
Ejemplo n.º 43
0
 public static void copyToPageLayerOut(AxMapControl axMapControl, AxPageLayoutControl axpageLayerOut)
 {
     IObjectCopy objectCopy = new ObjectCopyClass();
     object copyFromMap = axMapControl.Map;
     object copyMap = objectCopy.Copy(copyFromMap);
     object copyToMap = axpageLayerOut.ActiveView.FocusMap;
     objectCopy.Overwrite(copyMap, ref copyToMap);
 }
    /// <summary>
    /// Assigns the properties of src to the receiver.
    /// </summary>
    /// <param name="src"></param>
    public void Assign(IClone src)
    {
      //1. make sure that src is pointing to a valid object
      if (null == src)
      {
        throw new COMException("Invalid objact.");
      }

      //2. make sure that the type of src is of type 'ClonableObjClass'
      if (!(src is ClonableObjClass))
      {
        throw new COMException("Bad object type.");
      }

      //3. assign the properties of src to the current instance
      ClonableObjClass srcClonable = (ClonableObjClass)src;
      m_name = srcClonable.Name;
      m_version = srcClonable.Version;
      m_ID = new Guid(srcClonable.ID.ToString());

      //don't clone the spatial reference, since in this case we want both object to 
      //reference the same spatial reference (for example like features in a featureclass 
      //which share the same spatial reference)
      m_spatialRef = srcClonable.SpatialReference;

      //clone the point. Use deep cloning 
      if (null == srcClonable.Point)
        m_point = null;
      else
      {
        IObjectCopy objectCopy = new ObjectCopyClass();
        object obj = objectCopy.Copy((object)srcClonable.Point);
        m_point = (IPoint)obj;
      }

      m_arr = (ArrayList)srcClonable.ManagedArray.Clone();
    }
Ejemplo n.º 45
0
 private static IPolyline CopyPolyline(IPolyline line)
 {
     var objCopy = new ObjectCopyClass();
     var copy = objCopy.Copy(line) as IPolyline;
     return copy;
 }
Ejemplo n.º 46
0
        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //tabcontrol选择标签改变对应事件,mapcontrol和pagelayoutcontrol转换
            if (tabControl1.SelectedIndex == 1)
            {
                //mapcontrol和pagelayout交互
                IObjectCopy pOCopy = new ObjectCopyClass();
                System.Object pToCopyMap = axMapControl1.Map;
                System.Object pCopiedMap = pOCopy.Copy(pToCopyMap);
                System.Object pToOverMap = axPageLayoutControl1.ActiveView.FocusMap;
                pOCopy.Overwrite(pCopiedMap, ref pToOverMap);
                axPageLayoutControl1.ActiveView.Refresh();

                axPageLayoutControl1.Show();
                axMapControl1.Visible = false;

                pfrm.axToolbarControl5.SetBuddyControl(this.axPageLayoutControl1);

            }

            if (tabControl1.SelectedIndex == 0)
            {
                axMapControl1.Visible = true;
                axPageLayoutControl1.Visible = false;
            }
        }
Ejemplo n.º 47
0
        public void Execute(ESRI.ArcGIS.esriSystem.IArray paramvalues, ESRI.ArcGIS.esriSystem.ITrackCancel TrackCancel, ESRI.ArcGIS.Geoprocessing.IGPEnvironmentManager envMgr, ESRI.ArcGIS.Geodatabase.IGPMessages message)
        {
            try
            {
                IGPUtilities3 gpUtilities3 = new GPUtilitiesClass();

                if (TrackCancel == null)
                {
                    TrackCancel = new CancelTrackerClass();
                }

                // find feature class inside the given feature dataset
                IGPParameter osmFeatureDatasetParameter = paramvalues.get_Element(in_osmFeatureDatasetNumber) as IGPParameter;
                IDEFeatureDataset osmFeatureDataset = gpUtilities3.UnpackGPValue(osmFeatureDatasetParameter) as IDEFeatureDataset;

                string osmPointFeatureClassString = ((IDataElement)osmFeatureDataset).Name + "_osm_pt";
                string osmLineFeatureClassString = ((IDataElement)osmFeatureDataset).Name + "_osm_ln";
                string osmPolygonFeatureClassString = ((IDataElement)osmFeatureDataset).Name + "_osm_ply";

                IFeatureClass osmPointFeatureClass = gpUtilities3.OpenFeatureClassFromString(((IDataElement)osmFeatureDataset).CatalogPath + "/" + osmPointFeatureClassString);
                IFeatureClass osmLineFeatureClass = gpUtilities3.OpenFeatureClassFromString(((IDataElement)osmFeatureDataset).CatalogPath + "/" + osmLineFeatureClassString);
                IFeatureClass osmPoylgonFeatureClass = gpUtilities3.OpenFeatureClassFromString(((IDataElement)osmFeatureDataset).CatalogPath + "/" + osmPolygonFeatureClassString);

                // open the specified layers holding the symbology and editing templates
                IGPParameter osmPointSymbolTemplateParameter = paramvalues.get_Element(in_osmPointLayerNumber) as IGPParameter;
                IGPValue osmGPPointLayerValue = gpUtilities3.UnpackGPValue(osmPointSymbolTemplateParameter);

                IGPParameter outputPointGPParameter = paramvalues.get_Element(out_osmPointLayerNumber) as IGPParameter;
                IGPValue outputPointLayerGPValue = gpUtilities3.UnpackGPValue(outputPointGPParameter);

                bool isLayerOnDisk = false;

                // create a clone of the source layer
                // we will then go ahead and adjust the data source (dataset) of the cloned layer
                IObjectCopy objectCopy = new ObjectCopyClass();
                ICompositeLayer adjustedPointTemplateLayer = objectCopy.Copy(osmGPPointLayerValue) as ICompositeLayer;

                IGPGroupLayer osmPointGroupTemplateLayer = adjustedPointTemplateLayer as IGPGroupLayer;

                ICompositeLayer compositeLayer = gpUtilities3.Open((IGPValue)osmPointGroupTemplateLayer) as ICompositeLayer;
                //ICompositeLayer adjustedPointTemplateLayer = osmGPPointLayerValue as ICompositeLayer;
                //IGPGroupLayer osmPointGroupTemplateLayer = osmGPPointLayerValue as IGPGroupLayer;
                //IClone cloneSource = osmPointGroupTemplateLayer as IClone;
                //ICompositeLayer compositeLayer = m_gpUtilities3.Open((IGPValue)cloneSource.Clone()) as ICompositeLayer;

                if (compositeLayer == null)
                {
                    ILayerFactoryHelper layerFactoryHelper = new LayerFactoryHelperClass();
                    IFileName layerFileName = new FileNameClass();

                    layerFileName.Path = osmGPPointLayerValue.GetAsText();
                    IEnumLayer enumLayer = layerFactoryHelper.CreateLayersFromName((IName)layerFileName);
                    enumLayer.Reset();

                    compositeLayer = enumLayer.Next() as ICompositeLayer;

                    isLayerOnDisk = true;
                }

                IFeatureLayerDefinition2 featureLayerDefinition2 = null;
                ISQLSyntax sqlSyntax = null;

                IGPLayer adjustedPointGPLayer = null;

                if (compositeLayer != null)
                {
                    for (int layerIndex = 0; layerIndex < compositeLayer.Count; layerIndex++)
                    {

                        IFeatureLayer2 geoFeatureLayer = compositeLayer.get_Layer(layerIndex) as IFeatureLayer2;

                        if (geoFeatureLayer != null)
                        {
                            if (geoFeatureLayer.ShapeType == osmPointFeatureClass.ShapeType)
                            {
                                try
                                {
                                    ((IDataLayer2)geoFeatureLayer).Disconnect();
                                }
                                catch { }

                                ((IDataLayer2)geoFeatureLayer).DataSourceName = ((IDataset)osmPointFeatureClass).FullName;

                                ((IDataLayer2)geoFeatureLayer).Connect(((IDataset)osmPointFeatureClass).FullName);

                                featureLayerDefinition2 = geoFeatureLayer as IFeatureLayerDefinition2;
                                if (featureLayerDefinition2 != null)
                                {
                                    string queryDefinition = featureLayerDefinition2.DefinitionExpression;

                                    sqlSyntax = ((IDataset)osmPointFeatureClass).Workspace as ISQLSyntax;
                                    string delimiterIdentifier = sqlSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix);

                                    if (String.IsNullOrEmpty(queryDefinition) == false)
                                    {
                                        string stringToReplace = queryDefinition.Substring(0, 1);
                                        queryDefinition = queryDefinition.Replace(stringToReplace, delimiterIdentifier);
                                    }

                                    featureLayerDefinition2.DefinitionExpression = queryDefinition;
                                }
                            }
                        }
                    }

                    adjustedPointGPLayer = gpUtilities3.MakeGPLayerFromLayer((ILayer)compositeLayer);

                    // save the newly adjusted layer information to disk
                    if (isLayerOnDisk == true)
                    {
                        ILayerFile pointLayerFile = new LayerFileClass();
                        if (pointLayerFile.get_IsPresent(outputPointLayerGPValue.GetAsText()))
                        {
                            try
                            {
                                File.Delete(outputPointLayerGPValue.GetAsText());
                            }
                            catch (Exception ex)
                            {
                                message.AddError(120041,ex.Message);
                                return;
                            }
                        }

                        pointLayerFile.New(outputPointLayerGPValue.GetAsText());

                        pointLayerFile.ReplaceContents((ILayer)compositeLayer);

                        pointLayerFile.Save();

                        adjustedPointGPLayer = gpUtilities3.MakeGPLayerFromLayer((ILayer)pointLayerFile.Layer);
                    }

                 //   IGPLayer adjustedPointGPLayer = gpUtilities3.MakeGPLayerFromLayer((ILayer)compositeLayer);
                    gpUtilities3.AddInternalLayer2((ILayer)compositeLayer, adjustedPointGPLayer);
                    gpUtilities3.PackGPValue((IGPValue)adjustedPointGPLayer, outputPointGPParameter);

                }

                isLayerOnDisk = false;

                IGPParameter osmLineSymbolTemplateParameter = paramvalues.get_Element(in_osmLineLayerNumber) as IGPParameter;
                IGPValue osmGPLineLayerValue = gpUtilities3.UnpackGPValue(osmLineSymbolTemplateParameter) as IGPValue;

                IGPParameter outputLineGPParameter = paramvalues.get_Element(out_osmLineLayerNumber) as IGPParameter;
                IGPValue outputLineLayerGPValue = gpUtilities3.UnpackGPValue(outputLineGPParameter);

                IGPValue adjustedLineTemplateLayer = objectCopy.Copy(osmGPLineLayerValue) as IGPValue;

                IGPGroupLayer osmLineGroupTemplateLayer = adjustedLineTemplateLayer as IGPGroupLayer;

                compositeLayer = gpUtilities3.Open((IGPValue)osmLineGroupTemplateLayer) as ICompositeLayer;

                if (compositeLayer == null)
                {
                    ILayerFactoryHelper layerFactoryHelper = new LayerFactoryHelperClass();
                    IFileName layerFileName = new FileNameClass();

                    layerFileName.Path = osmGPLineLayerValue.GetAsText();
                    IEnumLayer enumLayer = layerFactoryHelper.CreateLayersFromName((IName)layerFileName);
                    enumLayer.Reset();

                    compositeLayer = enumLayer.Next() as ICompositeLayer;

                    isLayerOnDisk = true;
                }

                if (compositeLayer != null)
                {
                    for (int layerIndex = 0; layerIndex < compositeLayer.Count; layerIndex++)
                    {
                        IFeatureLayer2 geoFeatureLayer = compositeLayer.get_Layer(layerIndex) as IFeatureLayer2;
                        if (geoFeatureLayer.ShapeType == osmLineFeatureClass.ShapeType)
                        {
                            try
                            {
                                ((IDataLayer2)geoFeatureLayer).Disconnect();
                            }
                            catch { }
                            ((IDataLayer2)geoFeatureLayer).DataSourceName = ((IDataset)osmLineFeatureClass).FullName;
                            ((IDataLayer2)geoFeatureLayer).Connect(((IDataset)osmLineFeatureClass).FullName);

                            featureLayerDefinition2 = geoFeatureLayer as IFeatureLayerDefinition2;
                            if (featureLayerDefinition2 != null)
                            {
                                string queryDefinition = featureLayerDefinition2.DefinitionExpression;

                                sqlSyntax = ((IDataset)osmLineFeatureClass).Workspace as ISQLSyntax;
                                string delimiterIdentifier = sqlSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix);

                                if (string.IsNullOrEmpty(queryDefinition) == false)
                                {
                                    string stringToReplace = queryDefinition.Substring(0, 1);
                                    queryDefinition = queryDefinition.Replace(stringToReplace, delimiterIdentifier);
                                }

                                featureLayerDefinition2.DefinitionExpression = queryDefinition;
                            }
                        }
                    }

                    // save the newly adjusted layer information to disk
                    if (isLayerOnDisk == true)
                    {
                        ILayerFile lineLayerFile = new LayerFileClass();
                        if (lineLayerFile.get_IsPresent(outputLineLayerGPValue.GetAsText()))
                        {
                            try
                            {
                                File.Delete(outputLineLayerGPValue.GetAsText());
                            }
                            catch (Exception ex)
                            {
                                message.AddError(120042, ex.Message);
                                return;
                            }
                        }

                        lineLayerFile.New(outputLineLayerGPValue.GetAsText());

                        lineLayerFile.ReplaceContents((ILayer)compositeLayer);

                        lineLayerFile.Save();
                    }

                    IGPLayer adjustLineGPLayer = gpUtilities3.MakeGPLayerFromLayer((ILayer)compositeLayer);

                    gpUtilities3.AddInternalLayer2((ILayer)compositeLayer, adjustLineGPLayer);
                    gpUtilities3.PackGPValue((IGPValue)adjustLineGPLayer, outputLineGPParameter);
                }

                isLayerOnDisk = false;
                IGPParameter osmPolygonSymbolTemplateParameter = paramvalues.get_Element(in_osmPolygonLayerNumber) as IGPParameter;
                IGPValue osmGPPolygonLayerValue = gpUtilities3.UnpackGPValue(osmPolygonSymbolTemplateParameter);

                IGPParameter outputPolygonGPParameter = paramvalues.get_Element(out_osmPolygonLayerNumber) as IGPParameter;
                IGPValue outputPolygonLayerGPValue = gpUtilities3.UnpackGPValue(outputPolygonGPParameter);

                IGPValue adjustedPolygonTemplateLayer = objectCopy.Copy(osmGPPolygonLayerValue) as IGPValue;

                IGPGroupLayer osmPolygonGroupTemplateLayer = adjustedPolygonTemplateLayer as IGPGroupLayer;
                compositeLayer = gpUtilities3.Open((IGPValue)osmPolygonGroupTemplateLayer) as ICompositeLayer;

                if (compositeLayer == null)
                {
                    ILayerFactoryHelper layerFactoryHelper = new LayerFactoryHelperClass();
                    IFileName layerFileName = new FileNameClass();

                    layerFileName.Path = osmGPPolygonLayerValue.GetAsText();
                    IEnumLayer enumLayer = layerFactoryHelper.CreateLayersFromName((IName)layerFileName);
                    enumLayer.Reset();

                    compositeLayer = enumLayer.Next() as ICompositeLayer;

                    isLayerOnDisk = true;
                }

                if (compositeLayer != null)
                {
                    for (int layerIndex = 0; layerIndex < compositeLayer.Count; layerIndex++)
                    {
                        IFeatureLayer2 geoFeatureLayer = compositeLayer.get_Layer(layerIndex) as IFeatureLayer2;

                        if (geoFeatureLayer.ShapeType == osmPoylgonFeatureClass.ShapeType)
                        {
                            try
                            {
                                ((IDataLayer2)geoFeatureLayer).Disconnect();
                            }
                            catch { }
                            ((IDataLayer2)geoFeatureLayer).DataSourceName = ((IDataset)osmPoylgonFeatureClass).FullName;
                            ((IDataLayer2)geoFeatureLayer).Connect(((IDataset)osmPoylgonFeatureClass).FullName);

                            featureLayerDefinition2 = geoFeatureLayer as IFeatureLayerDefinition2;
                            if (featureLayerDefinition2 != null)
                            {
                                string queryDefinition = featureLayerDefinition2.DefinitionExpression;

                                sqlSyntax = ((IDataset)osmPoylgonFeatureClass).Workspace as ISQLSyntax;
                                string delimiterIdentifier = sqlSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix);

                                if (String.IsNullOrEmpty(queryDefinition) == false)
                                {
                                    string stringToReplace = queryDefinition.Substring(0, 1);
                                    queryDefinition = queryDefinition.Replace(stringToReplace, delimiterIdentifier);
                                }

                                featureLayerDefinition2.DefinitionExpression = queryDefinition;
                            }
                        }
                    }

                    // save the newly adjusted layer information to disk
                    if (isLayerOnDisk == true)
                    {
                        ILayerFile polygonLayerFile = new LayerFileClass();
                        if (polygonLayerFile.get_IsPresent(outputPolygonLayerGPValue.GetAsText()))
                        {
                            try
                            {
                                File.Delete(outputPolygonLayerGPValue.GetAsText());
                            }
                            catch (Exception ex)
                            {
                                message.AddError(120043, ex.Message);
                                return;
                            }
                        }

                        polygonLayerFile.New(outputPolygonLayerGPValue.GetAsText());

                        polygonLayerFile.ReplaceContents((ILayer)compositeLayer);

                        polygonLayerFile.Save();
                    }

                    IGPLayer adjustedPolygonGPLayer = gpUtilities3.MakeGPLayerFromLayer((ILayer)compositeLayer);
                    gpUtilities3.AddInternalLayer2((ILayer)compositeLayer, adjustedPolygonGPLayer);

                    gpUtilities3.PackGPValue((IGPValue)adjustedPolygonGPLayer, outputPolygonGPParameter);
                }
            }
            catch (Exception ex)
            {
                message.AddError(-10,ex.Message);
            }
        }
Ejemplo n.º 48
0
 private void MapCopy()
 {
     if (GIS.Common.DataEditCommon.g_pAxMapControl != null)
     {
         IObjectCopy objCopy = new ObjectCopyClass();
         object toCopyMap = GIS.Common.DataEditCommon.g_pMyMapCtrl.ActiveView.FocusMap;
         object copiedMap = objCopy.Copy(toCopyMap);
         object overwriteMap = axPageLayoutControl1.ActiveView.FocusMap;
         objCopy.Overwrite(toCopyMap, ref overwriteMap);
     }
 }