Beispiel #1
0
 private void RefreshMap()
 {
     //added by jin
     try
     {
         cboActiveMap.Items.Clear();
         //  MessageBox.Show("Map is replaced");
         //Method 1: Open MapDocument file to get information about maps
         // m_mapDocument.Open(m_mapDocuemntName, "");
         //Method 2: Get information about maps from MapControl3
         m_mapDocument.Open(m_mapControl.DocumentFilename, "");
         for (int i = 0; i < m_mapDocument.MapCount; i++)
         {
             string item = m_mapDocument.get_Map(i).Name;
             cboActiveMap.Items.Add(item);
         }
         //Initialization
         cboActiveMap.Text = m_mapDocument.get_Map(0).Name;
         //The exception will be throwed,but it runes successfully in Exercise 5, may be a trouble for thread running
         //axMapControl1.Map = m_mapDocument.get_Map(0);
         //axMapControl1.Map = m_mapDocument.ActiveView.FocusMap;
         m_mapDocument.Close();
         //   axMapControl1.Refresh();
         // axTOCControl1.Update();
         AddLayersToComboBox();
     }
     catch (StackOverflowException se)
     {
         Console.WriteLine(se.Message);
     }
 }
Beispiel #2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (checkedMDData.Items.Count == 0)
            {
                MessageBox.Show("请指定数据源!", "提示!"); return;
            }
            if (txtPath.Text == "")
            {
                MessageBox.Show("请指定输出路径!", "提示!"); return;
            }
            IActiveView pActiveView;

            SysCommon.CProgress vProgress = new SysCommon.CProgress("进度条");
            vProgress.EnableCancel    = true;//设置进度条
            vProgress.ShowDescription = true;
            vProgress.FakeProgress    = false;
            vProgress.TopMost         = true;
            vProgress.MaxValue        = checkedMDData.Items.Count;
            //vProgress.EnableUserCancel(true);
            vProgress.ShowProgress();
            try
            {
                //string jpgDir = "";
                for (int i = 0; i < checkedMDData.Items.Count; i++)
                {
                    vProgress.ProgresssValue = i + 1;
                    if (checkedMDData.GetItemChecked(i))
                    {
                        string sFilePath = checkedMDData.Items[i].ToString();
                        //jpgDir = System.IO.Path.GetDirectoryName(sFilePath);
                        string jpgFileName = System.IO.Path.GetFileNameWithoutExtension(sFilePath) + ".jpg";
                        vProgress.SetProgress("正在导出图片:" + jpgFileName);
                        OpenDocument(sFilePath);
                        pActiveView = m_MapDocument.ActiveView;
                        //ExportJPG(pActiveView, Convert.ToInt32(UpDownResolution.Value), txtPath.Text, sFilePath);
                        CommandExportActiveView pCmd = new CommandExportActiveView(Convert.ToInt32(UpDownResolution.Value), 1, txtPath.Text + "\\" + jpgFileName, "JPG", false);
                        pCmd.ExportActiveView = pActiveView;
                        pCmd.OnClick();
                    }
                }
                if (this.WriteLog)
                {
                    Plugin.LogTable.Writelog("输出图片完成!保存在: " + txtPath.Text);
                }
                this.Close();
                this.Dispose();
            }
            catch { MessageBox.Show("图片导出失败!", "提示!"); }
            finally
            {
                m_MapDocument.Close();
                m_MapDocument = null;
                vProgress.Close();
            }
        }
Beispiel #3
0
 private void frmAddProjectLayers_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (mapDoc != null)
     {
         mapDoc.Close();
     }
 }
Beispiel #4
0
        //退出程序
        public void ExitProgram(AxMapControl axMapControl1, AxTOCControl axTOCControl1)
        {
            DialogResult dialogResult = MessageBox.Show("保存文件?", "关闭文件", MessageBoxButtons.YesNoCancel);

            if (dialogResult == DialogResult.Yes)
            {
                SaveDocument(axMapControl1);
                mapDocument.Close();
                axMapControl1.ClearLayers();
                axMapControl1.Refresh();
                axTOCControl1.Update();
                Application.Exit();
            }
            if (dialogResult == DialogResult.No)
            {
                //mapDocument.Close();
                //axMapControl1.ClearLayers();
                //axMapControl1.Refresh();
                //axTOCControl1.Update();
                Application.Exit();
            }
            if (dialogResult == DialogResult.Cancel)
            {
                return;
            }
        }
Beispiel #5
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (m_pPageLayoutCtl == null)
            {
                return;
            }

            string strFullpath = txtFolder.Text;

            if (strFullpath[strFullpath.Length - 1] != System.IO.Path.DirectorySeparatorChar)
            {
                strFullpath += System.IO.Path.DirectorySeparatorChar;
            }

            string strDocName = CreateMxdFolderAndGDB(strFullpath, m_pPageLayoutCtl.DocumentFilename);

            string strFullGdbName = strFullpath + strDocName + ".gdb";
            string strFullDocName = strFullpath + strDocName + ".mxd";
            //另存地图文档
            ClsGDBDataCommon cls = new ClsGDBDataCommon();

            m_pMapDoc = cls.SaveAsDocument(m_pPageLayoutCtl, strFullDocName);
            //n
            if (ExportLayers(m_pMapDoc, strFullGdbName, radioLayer.Checked))
            {
                m_pMapDoc.Save(true, false);
                m_strDocNameNew = m_pMapDoc.DocumentFilename;
                m_pMapDoc.Close();

                MessageBox.Show("导出成功!");
            }
        }
Beispiel #6
0
        /// <summary>
        /// 根据地图出图配置,设置地图文档并出图
        /// </summary>
        /// <param name="cfg">对地图进行各项配置和出图的信息</param>
        /// <param name="mapDoc">要设置并出图的地图文档,若值为null则根据<see cref="cfg"/>参数指定的信息
        /// 复制地图模板到生成目录或临时目录,打开复制后的地图文档进行设置和出图</param>
        public virtual void ExportMap(MapExportInfo cfg, IMapDocument mapDoc = null)
        {
            //是否在完成出图后关闭地图文档,地图文档来自外部传参(mapDoc != null)则不关闭,来自内部打开则应关闭
            bool closeMapDoc = mapDoc == null;

            try
            {
                if (!ValidateConfig(cfg, out var message))
                {
                    throw new Exception(message);
                }
                if (mapDoc == null)
                {
                    mapDoc = GetMapDocument(cfg);
                }
                ExportMapMainOperation(cfg, mapDoc);
            }
            catch (Exception ex)
            {
                if (closeMapDoc && mapDoc != null)
                {
                    mapDoc.Close();
                    Marshal.ReleaseComObject(mapDoc);
                }
                throw ex;
            }
        }
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (MessageBox.Show("Are you sure the exit system?", "Exit system", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         SaveToolbarControlItems(filenameforToolbar);
         try
         {
             mapdocument.Close();
         }
         catch (Exception)
         {
         }
         Application.ExitThread();
         Application.Exit();
     }
 }
Beispiel #8
0
        /// <summary>
        /// 根据地图出图配置,设置地图文档并导出地图
        /// </summary>
        /// <param name="cfg"></param>
        /// <param name="mapDoc"></param>
        protected virtual void ExportMapMainOperation(MapExportInfo cfg, IMapDocument mapDoc)
        {
            //设置数据源、定义查询、比例尺、显示范围
            var graphicsContainer = mapDoc.PageLayout as IGraphicsContainer;

            foreach (var mapFrameInfo in cfg.MapFrames)
            {
                SetMapFrame(graphicsContainer, mapFrameInfo);
            }

            //设置元素的值
            foreach (var elementInfo in cfg.Elements)
            {
                var elements = graphicsContainer.GetElementsByKeyword(elementInfo.Name);
                SetElementsValue(elements, elementInfo.ValueType, elementInfo.Value);
            }

            //保存地图,导出图片
            mapDoc.Save();
            foreach (var exportPicture in cfg.ExportPictures)
            {
                var outputPath = Path.Combine(cfg.ExportDirectory, cfg.ExportFileName + exportPicture.PicExtension);
                mapDoc.PageLayout.ExportToPicture(outputPath, exportPicture.Dpi);
            }

            //关闭文档,释放资源
            mapDoc.Close();
            Marshal.ReleaseComObject(mapDoc);
        }
Beispiel #9
0
 private void frmTileImageServiceLayer_FormClosed(object sender, FormClosedEventArgs e)
 {
     if (mapDoc != null)
     {
         mapDoc.Close();
     }
 }
        public async Task LoadAsync()
        {
            IMapDocument mapDoc = await MapUtilities.GetMapDocumentFromFileNameAsync(_path);

            await Task.Run(() =>
            {
                // This will read the open map document, which may do blocking IO
                LoadMaps(mapDoc);
            });

            mapDoc.Close();
        }
Beispiel #11
0
 private void SaveMXD(string sName, ESRI.ArcGIS.Carto.IMap map)
 {
     try
     {
         _pMapDocument.Save(true, false);
     }
     catch
     {
         _pMapDocument.Save(false, false);
     }
     _pMapDocument.Close();
 }
Beispiel #12
0
        private void Save_btn_Click(object sender, EventArgs e)
        {
            if (axMapControl1.DocumentFilename == null)
            {
                SaveMapAs();
            }
            if (m_bDocModified == false)
            {
                return;
            }
            try
            {
                if (axMapControl1.Map.LayerCount == 0)
                {
                    return;
                }
                if (axMapControl1.DocumentFilename != null && axMapControl1.CheckMxFile(axMapControl1.DocumentFilename))
                {
                    if (m_pMapDocument != null)
                    {
                        m_pMapDocument.Close();
                        m_pMapDocument = null;
                    }
                    m_pMapDocument = new MapDocumentClass();                            //实例化
                    m_pMapDocument.Open(axMapControl1.DocumentFilename, "");            //必须的一步,用于将AxMapControl的实例的DocumentFileName传递给pMapDoc的
                    if (m_pMapDocument.get_IsReadOnly(m_pMapDocument.DocumentFilename)) //判断是否只读
                    {
                        MessageBox.Show("文件只读!", "失败", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        m_pMapDocument.Close();
                        return;
                    }
                    m_pMapDocument.ReplaceContents((IMxdContents)axMapControl1.Map); //重置
                    IObjectCopy lip_ObjCopy = new ObjectCopyClass();                 //使用Copy,避免共享引用
                    axMapControl1.Map = (IMap)lip_ObjCopy.Copy(m_pMapDocument.get_Map(0));
                    lip_ObjCopy       = null;
                    m_pMapDocument.Save(m_pMapDocument.UsesRelativePaths, true);
                    axMapControl1.DocumentFilename = m_pMapDocument.DocumentFilename;
                    this.Text      = this.Text + "  -  " + axMapControl1.DocumentFilename;
                    m_bDocModified = false;

                    FileInfo fi = new FileInfo(m_pMapDocument.DocumentFilename);
                    Global.m_sMxdPath = fi.GetDirectory();
                    MessageBox.Show("保存完成!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string filter = "Map document (*.mxd)|*.mxd";

            saveFileDialog1.Filter = filter;
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string filename = saveFileDialog1.FileName;
                //mxdocument = new MxDocumentClass();
                mapdocument = new MapDocument();
                mapdocument.New(filename);
                mapdocument.SaveAs(filename);
                mapdocument.Close();
                LoadMxdFile(filename);
            }
        }
Beispiel #14
0
 public bool LoadMapDocument(ref IPageLayout pPageLayout, string sFileName, string sPassword)
 {
     try
     {
         if (sFileName == null)
         {
             sFileName = "";
         }
         if (sPassword == null)
         {
             sPassword = "";
         }
         if (pPageLayout == null)
         {
             MessageBox.Show("地图文档加载失败,PageLayout 加载失败。", "错误警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             return(false);
         }
         IMapDocument document = null;
         document = this.OpenMapDocument(sFileName, sPassword);
         if (document == null)
         {
             return(false);
         }
         pPageLayout = document.PageLayout;
         document.Close();
         document = null;
         IActiveView view = pPageLayout as IActiveView;
         if (view.GraphicsContainer != null)
         {
             IViewManager manager          = view as IViewManager;
             ISelection   elementSelection = manager.ElementSelection;
             view.Selection = elementSelection;
         }
         return(true);
     }
     catch (Exception exception)
     {
         this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.CoreFun", "LoadMapDocument", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
         return(false);
     }
 }
Beispiel #15
0
 public bool LoadMapDocument(ref IMap pMap, string sFileName, string sPassword)
 {
     try
     {
         if (sFileName == null)
         {
             sFileName = "";
         }
         if (sPassword == null)
         {
             sPassword = "";
         }
         if (pMap == null)
         {
             Interaction.MsgBox("地图文档加载失败,Map 加载失败。", MsgBoxStyle.Exclamation, "错误警告");
             return(false);
         }
         IMapDocument document = null;
         document = this.OpenMapDocument(sFileName, sPassword);
         if (document == null)
         {
             return(false);
         }
         pMap = document.get_Map(0);
         document.Close();
         document = null;
         IActiveView view = pMap as IActiveView;
         if (view.GraphicsContainer != null)
         {
             IViewManager manager          = view as IViewManager;
             ISelection   elementSelection = manager.ElementSelection;
             view.Selection = elementSelection;
         }
         return(true);
     }
     catch (Exception exception)
     {
         this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.CoreFun", "LoadMapDocument", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
         return(false);
     }
 }
Beispiel #16
0
        public MXD(string mxdPath)
        {
            path = mxdPath;
            // GUIDs finden: http://support.esri.com/index.cfm?fa=knowledgebase.techarticles.articleShow&d=31115
            LayerTypeUIDs[0] = "{EDAD6644-1810-11D1-86AE-0000F8751720}";
            LayerTypeUIDs[1] = "{5CEAE408-4C0A-437F-9DB3-054D83919850}";
            LayerTypeUIDs[2] = "{DBCA59AC-6771-4408-8F48-C7D53389440C}";
            LayerTypeUIDs[3] = "{D02371C7-35F7-11D2-B1F2-00C04F8EDEFF}";
            LayerTypeUIDs[4] = "{605BC37A-15E9-40A0-90FB-DE4CC376838C}";
            LayerTypeUIDs[5] = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}";
            LayerTypeUIDs[6] = "";

            if (InitializeLicense() == esriLicenseStatus.esriLicenseCheckedOut)
            {
                mapDoc = new MapDocumentClass();
                if (mapDoc.get_IsPresent(path))
                {
                    if (mapDoc.get_IsMapDocument(path))
                    {
                        mapDoc.Open(path, null);
                        if (mapDoc.DocumentType == esriMapDocumentType.esriMapDocumentTypeMxd)
                        {
                            activateMapDocument();

                            // alle Layer holen
                            layerList = getLayerList(null);

                            // alle GroupLayer holen
                            processLayer(LayerTypes.GroupLayer);

                            // alle AnnotationLayer holen
                            processLayer(LayerTypes.AnnotationLayer);

                            // alle AnnotationSubLayer holen
                            processLayer(LayerTypes.AnnotationSubLayer);

                            // alle RasterLayer holen
                            processLayer(LayerTypes.RasterLayer);

                            // alle RasterCatalogLayer holen
                            processLayer(LayerTypes.RasterCatalogLayer);

                            // alle FeatureLayer holen
                            processLayer(LayerTypes.FeatureLayer);

                            // übrige Layer holen
                            foreach (ILayer lyr in layerList)
                            {
                                if (!processedLayers.Contains(lyr))
                                {
                                    LayerInfo lyrInfo = new LayerInfo(mapDoc);
                                    lyrInfo.processOtherLayer(lyr);
                                    lyrInfos.Add(lyrInfo);
                                    processedLayers.Add(lyr);
                                }
                            }

                            // Resultate ausgeben
                            foreach (LayerInfo info in lyrInfos)
                            {
                                Console.WriteLine(info.writeCSV());
                            }

                            // Dokument schliessen
                            mapDoc.Close();

                        } else {
                            Console.Error.WriteLine("FEHLER: kein gültiges MXD-File");
                        }
                    } else {
                        Console.Error.WriteLine("FEHLER: kein gültiges MXD-File");
                    }
                } else {
                    Console.Error.WriteLine("FEHLER: Angegebenes File nicht gefunden");
                }

            } else
            {
                Console.Error.WriteLine("FEHLER: Keine ArcView-Lizenz verfügbar");
            }

            // Lizenz zurückgeben
            TerminateLicense();
        }
Beispiel #17
0
        public MXD(string mxdPath)
        {
            path = mxdPath;
            // GUIDs finden: http://support.esri.com/index.cfm?fa=knowledgebase.techarticles.articleShow&d=31115
            LayerTypeUIDs[0] = "{EDAD6644-1810-11D1-86AE-0000F8751720}";
            LayerTypeUIDs[1] = "{5CEAE408-4C0A-437F-9DB3-054D83919850}";
            LayerTypeUIDs[2] = "{DBCA59AC-6771-4408-8F48-C7D53389440C}";
            LayerTypeUIDs[3] = "{D02371C7-35F7-11D2-B1F2-00C04F8EDEFF}";
            LayerTypeUIDs[4] = "{605BC37A-15E9-40A0-90FB-DE4CC376838C}";
            LayerTypeUIDs[5] = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}";
            LayerTypeUIDs[6] = "";

            if (InitializeLicense() == esriLicenseStatus.esriLicenseCheckedOut)
            {
                mapDoc = new MapDocumentClass();
                if (mapDoc.get_IsPresent(path))
                {
                    if (mapDoc.get_IsMapDocument(path))
                    {
                        mapDoc.Open(path, null);
                        if (mapDoc.DocumentType == esriMapDocumentType.esriMapDocumentTypeMxd)
                        {
                            activateMapDocument();

                            // alle Layer holen
                            layerList = getLayerList(null);

                            // alle GroupLayer holen
                            processLayer(LayerTypes.GroupLayer);

                            // alle AnnotationLayer holen
                            processLayer(LayerTypes.AnnotationLayer);

                            // alle AnnotationSubLayer holen
                            processLayer(LayerTypes.AnnotationSubLayer);

                            // alle RasterLayer holen
                            processLayer(LayerTypes.RasterLayer);

                            // alle RasterCatalogLayer holen
                            processLayer(LayerTypes.RasterCatalogLayer);

                            // alle FeatureLayer holen
                            processLayer(LayerTypes.FeatureLayer);

                            // übrige Layer holen
                            foreach (ILayer lyr in layerList)
                            {
                                if (!processedLayers.Contains(lyr))
                                {
                                    LayerInfo lyrInfo = new LayerInfo(mapDoc);
                                    lyrInfo.processOtherLayer(lyr);
                                    lyrInfos.Add(lyrInfo);
                                    processedLayers.Add(lyr);
                                }
                            }

                            // Resultate ausgeben
                            foreach (LayerInfo info in lyrInfos)
                            {
                                Console.WriteLine(info.writeCSV());
                            }

                            // Dokument schliessen
                            mapDoc.Close();
                        }
                        else
                        {
                            Console.Error.WriteLine("FEHLER: kein gültiges MXD-File");
                        }
                    }
                    else
                    {
                        Console.Error.WriteLine("FEHLER: kein gültiges MXD-File");
                    }
                }
                else
                {
                    Console.Error.WriteLine("FEHLER: Angegebenes File nicht gefunden");
                }
            }
            else
            {
                Console.Error.WriteLine("FEHLER: Keine ArcView-Lizenz verfügbar");
            }

            // Lizenz zurückgeben
            TerminateLicense();
        }