private void cmd_SaveDoc(System.Object sender, EventArgs e) { if (m_MapControl.CheckMxFile(m_MapControl.DocumentFilename)) { //create a new instance of a MapDocument IMapDocument mapDoc = new MapDocumentClass(); mapDoc.Open(m_MapControl.DocumentFilename, string.Empty); //Make sure that the MapDocument is not readonly if (mapDoc.get_IsReadOnly(m_MapControl.DocumentFilename)) { MessageBox.Show("地图为只读!"); mapDoc.Close(); return; } //Replace its contents with the current map mapDoc.ReplaceContents((IMxdContents)m_MapControl.Map); //save the MapDocument in order to persist it mapDoc.Save(mapDoc.UsesRelativePaths, false); //close the MapDocument mapDoc.Close(); } }
private void BtnSaveMXD_Click(object sender, EventArgs e) { //make sure that the current MapDoc is valid first if (m_documentFileName != string.Empty && m_mapControl.CheckMxFile(m_documentFileName)) { //create a new instance of a MapDocument class IMapDocument mapDoc = new MapDocumentClass(); //Open the current document into the MapDocument mapDoc.Open(m_documentFileName, string.Empty); //Make sure that the MapDocument is not readonly if (mapDoc.get_IsReadOnly(m_documentFileName)) { MessageBox.Show("سند فقط خواندنی است"); mapDoc.Close(); return; } //Replace the map with the one of the PageLayout mapDoc.ReplaceContents((IMxdContents)m_pageLayoutControl.PageLayout); //save the document mapDoc.Save(mapDoc.UsesRelativePaths, false); mapDoc.Close(); } }
private void menuSaveDoc_Click(object sender, EventArgs e) { //execute Save Document command if (m_mapControl.CheckMxFile(m_mapDocumentName)) { //create a new instance of a MapDocument IMapDocument mapDoc = new MapDocumentClass(); mapDoc.Open(m_mapDocumentName, string.Empty); //Make sure that the MapDocument is not readonly if (mapDoc.get_IsReadOnly(m_mapDocumentName)) { MessageBox.Show("Map document is read only!"); mapDoc.Close(); return; } //Replace its contents with the current map mapDoc.ReplaceContents((IMxdContents)m_mapControl.Map); //save the MapDocument in order to persist it mapDoc.Save(mapDoc.UsesRelativePaths, false); //close the MapDocument mapDoc.Close(); } }
//保存地图文档 public static void SaveMapDocument(ESRI.ArcGIS.Controls.AxMapControl axMapControl) { if (axMapControl == null) { return; } string m_mapDocumentName = axMapControl.DocumentFilename; if (axMapControl.CheckMxFile(m_mapDocumentName)) { //新建地图文档接口 IMapDocument mapDoc = new MapDocumentClass(); mapDoc.Open(m_mapDocumentName, string.Empty); //确定文档非只读文件 if (mapDoc.get_IsReadOnly(m_mapDocumentName)) { MessageBox.Show("Map document is read only!"); mapDoc.Close(); return; } //用当前地图替换文档内容 mapDoc.ReplaceContents((IMxdContents)axMapControl.Map); //保存文档 mapDoc.Save(mapDoc.UsesRelativePaths, false); //关闭文档 mapDoc.Close(); } }
private void SaveDocument() { try { if (mapControl.CheckMxFile(m_mapDocumentName)) { //使用MapDocument对象保存文件 IMapDocument mapDocument = new MapDocumentClass(); mapDocument.Open(m_mapDocumentName, string.Empty); //判断文件是不是只读的 if (mapDocument.get_IsReadOnly(m_mapDocumentName)) { MessageBox.Show("地图文件是只读的!"); mapDocument.Close(); return; } //替换已有的文件 mapDocument.ReplaceContents((IMxdContents)mapControl.Map); //保存文件 mapDocument.Save(mapDocument.UsesRelativePaths, false); mapDocument.Close(); } } catch (Exception e) { MessageBox.Show(e.Message); } }
private void barButtonItem25_ItemClick(object sender, ItemClickEventArgs e) { string m_currentMapDocument = axMapControl1.DocumentFilename; //execute Save Document command if (axMapControl1.CheckMxFile(m_currentMapDocument)) { //create a new instance of a MapDocument IMapDocument mapDoc = new MapDocumentClass(); mapDoc.Open(m_currentMapDocument, string.Empty); //Make sure that the MapDocument is not readonly if (mapDoc.get_IsReadOnly(m_currentMapDocument)) { MessageBox.Show("Map document is read only!"); mapDoc.Close(); return; } //Replace its contents with the current map mapDoc.ReplaceContents((IMxdContents)axMapControl1.Map); //save the MapDocument in order to persist it mapDoc.Save(mapDoc.UsesRelativePaths, false); //close the MapDocument mapDoc.Close(); MessageBox.Show("保存地图文档成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { MessageBox.Show(m_currentMapDocument + "不是有效的地图文档!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void OnClick() { //// 首先确认当前地图文档是否有效 //if (null != m_pageLayoutControl.DocumentFilename && m_mapControl.CheckMxFile(m_pageLayoutControl.DocumentFilename)) //{ //// 创建一个新的地图文档实例 //IMapDocument mapDoc = new MapDocumentClass(); // 打开当前地图文档 //mapDoc.Open(m_pageLayoutControl.DocumentFilename, string.Empty); // 用 PageLayout 中的文档替换当前文档中的 PageLayout 部分 //mapDoc.ReplaceContents((IMxdContents)m_pageLayoutControl.PageLayout); // 保存地图文档 //mapDoc.Save(mapDoc.UsesRelativePaths, false); //mapDoc.Close(); //m_mapDocument = this.hk.Document; //if (m_mapDocument.get_IsReadOnly(m_mapDocument.DocumentFilename)) //{ // MessageBox.Show("This map document is read only!"); // return; //} //m_mapDocument.Save(m_mapDocument.UsesRelativePaths, true); //MessageBox.Show("Changes saved successfully!"); //execute Save Document command //m_mapDocumentName = m_mapControl.DocumentFilename; if (m_mapControl.DocumentFilename != null && m_mapControl.CheckMxFile(m_mapDocumentName)) { //m_mapControl.CheckMxFile(m_mapDocumentName); //create a new instance of a MapDocument IMapDocument mapDoc = new MapDocumentClass(); mapDoc.Open(m_mapDocumentName, string.Empty); //Make sure that the MapDocument is not readonly if (mapDoc.get_IsReadOnly(m_mapDocumentName)) { MessageBox.Show("Map document is read only!"); mapDoc.Close(); return; } //Replace its contents with the current map mapDoc.ReplaceContents((IMxdContents)m_mapControl.Map); //save the MapDocument in order to persist it mapDoc.Save(mapDoc.UsesRelativePaths, false); //close the MapDocument mapDoc.Close(); } else { cmd = new ControlsSaveAsDocCommandClass(); cmd.OnCreate(this.m_mapControl); cmd.OnClick(); } }
private void button5_Click(object sender, EventArgs e) { if (axMapControl1.DocumentMap == null) { MessageBox.Show("地图文档不能为空", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { try { IMapDocument pMapDocument = new MapDocumentClass(); string saveFileName = axMapControl1.DocumentFilename; if (saveFileName != "" && axMapControl1.CheckMxFile(saveFileName)) { if (pMapDocument.get_IsReadOnly(saveFileName)) { MessageBox.Show("本地图文档只读的,不能保存!"); pMapDocument.Close(); return; } else { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Title = "保存文档"; saveFileDialog.Filter = "MXD文档(*.mxd)|*.mxd"; string fileName = System.IO.Path.GetFileName(saveFileName); saveFileDialog.FileName = fileName; if (saveFileDialog.ShowDialog() == DialogResult.OK) { saveFileName = saveFileDialog.FileName; pMapDocument.New(saveFileName); pMapDocument.ReplaceContents(axMapControl1.Map as IMxdContents); pMapDocument.Save(true, true); pMapDocument.Close(); MessageBox.Show("保存成功!"); } else { pMapDocument.Close(); return; } } } else { MessageBox.Show("无法保存!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
public static void save_doc() { try { string filename = mainForm.mainform.mainMapControl.DocumentFilename; IMapDocument pMapDocument = new MapDocumentClass(); if (filename != null && mainForm.mainform.mainMapControl.CheckMxFile(filename)) { if (pMapDocument.get_IsReadOnly(filename)) {//地图文档只读 MessageBox.Show("该地图文档是只读的,无保存权限!", "信息提示", MessageBoxButtons.OK); pMapDocument.Close(); return; } } else {//地图文档为空,创建地图文档 //实例化SaveFileDialog SaveFileDialog pSaveFileDialog = new SaveFileDialog { Title = "请选择保存路径", OverwritePrompt = true, RestoreDirectory = true, Filter = "ArcMap文档(*.mxd)|*.mxd" }; if (pSaveFileDialog.ShowDialog() == DialogResult.OK) { filename = pSaveFileDialog.FileName; return; } else { return; } } //统一保存地图文档 pMapDocument.New(filename); pMapDocument.ReplaceContents(mainForm.mainform.mainMapControl.Map as IMxdContents); pMapDocument.Save(pMapDocument.UsesRelativePaths, true); pMapDocument.Close(); MessageBox.Show("保存地图文档成功!", "信息提示", MessageBoxButtons.OK); } catch (Exception exc) { MessageBox.Show("地图文档保存失败!" + exc.Message, "信息提示", MessageBoxButtons.OK); } }
public static void SaveDocument() { try { string sMxdFileName = Form1.form1.axMapControl1.DocumentFilename; IMapDocument pMapDocument = new MapDocumentClass(); if (sMxdFileName != null && Form1.form1.axMapControl1.CheckMxFile(sMxdFileName)) { if (pMapDocument.get_IsReadOnly(sMxdFileName)) { MessageBox.Show("本地图文档是只读的,不能保存!"); pMapDocument.Close(); return; } } else { SaveFileDialog pSaveFileDialog = new SaveFileDialog { Title = "请选择保存路径", OverwritePrompt = true, Filter = "ArcMap文档(*.mxd)|*.mxd|ArcMap模板(*.mxt)|*.mxt", RestoreDirectory = true }; if (pSaveFileDialog.ShowDialog() == DialogResult.OK) { sMxdFileName = pSaveFileDialog.FileName; } else { return; } } pMapDocument.New(sMxdFileName); pMapDocument.ReplaceContents(Form1.form1.axMapControl1.Map as IMxdContents); pMapDocument.Save(pMapDocument.UsesRelativePaths, true); pMapDocument.Close(); MessageBox.Show("保存地图文档成功!"); } catch (Exception ex) { MessageBox.Show(ex.Message); } //ICommand command = new ControlsSaveAsDocCommandClass(); //command.OnCreate(Form1.form1.axMapControl1.Object); //command.OnClick(); }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { // TODO: Add OpenDocument.OnClick implementation OpenFileDialog dlg = new OpenFileDialog(); dlg.Title = "选择地图文档"; dlg.Filter = "地图文档(*.mxd)|*.mxd"; string docName = null; if (dlg.ShowDialog() == DialogResult.OK) { docName = dlg.FileName; IMapDocument mapDoc = new MapDocumentClass(); if (mapDoc.get_IsMapDocument(docName)) { mapDoc.Open(docName, string.Empty); IMap map = mapDoc.get_Map(0); m_ControlsSynchronizer.ReplaceMap(map); mapDoc.Close(); RecnetFilesList.Add(docName); } else { MessageBox.Show("不可用的地图文档", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); RecnetFilesList.Remove(docName); } } }
private void SaveAsItem_Click(object sender, EventArgs e) { try { SaveFileDialog dlg = new SaveFileDialog(); dlg.RestoreDirectory = true; dlg.Filter = "地图文档(*.mxd)|*.mxd"; dlg.AddExtension = true; if (dlg.ShowDialog() == DialogResult.OK) { string mxdpath = dlg.FileName; if (string.IsNullOrEmpty(mxdpath)) { return; } IMapDocument mapDoc = new MapDocumentClass(); mapDoc.New(mxdpath); mapDoc.ReplaceContents(this.axMapcontrol.Map as IMxdContents); mapDoc.Save(true, true); mapDoc.Close(); MessageBox.Show("保存成功"); } } catch (Exception ex) { MessageBox.Show("保存失败" + ex.Message); } }
private void Save_Click(object sender, EventArgs e) { //execute Save Document command if (m_mapControl.CheckMxFile(m_mapDocumentName)) { { //create a new instance of a MapDocument IMapDocument mapDoc = new MapDocumentClass(); mapDoc.Open(m_mapDocumentName, string.Empty); //Make sure that the MapDocument is not readonly if (mapDoc.get_IsReadOnly(m_mapDocumentName)) { { MessageBox.Show("Map document is read only!"); mapDoc.Close(); return; } } } } }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { //launch a new OpenFile dialog OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "Map Documents (*.mxd)|*.mxd"; dlg.Multiselect = false; dlg.Title = "Open Map Document"; if (dlg.ShowDialog() == DialogResult.OK) { string docName = dlg.FileName; IMapDocument mapDoc = new MapDocumentClass(); if (mapDoc.get_IsPresent(docName) && !mapDoc.get_IsPasswordProtected(docName)) { mapDoc.Open(docName, string.Empty); // set the first map as the active view IMap map = mapDoc.get_Map(0); mapDoc.SetActiveView((IActiveView)map); m_controlsSynchronizer.PageLayoutControl.PageLayout = mapDoc.PageLayout; m_controlsSynchronizer.ReplaceMap(map); mapDoc.Close(); m_sDocumentPath = docName; } } }
public static void SaveMxd() { IMapDocument oMapDoc = new MapDocumentClass(); oMapDoc.Open(AxMapControl.DocumentFilename); if (oMapDoc.IsReadOnly[AxMapControl.DocumentFilename]) { throw new InvalidOperationException("Can not save mxd. Is read only."); } AxMapControl.Update(); AxTocControl.Update(); oMapDoc.ReplaceContents((IMxdContents)AxMapControl.Map); oMapDoc.Save(true, true); oMapDoc.Close(); if (oMapDoc != null) { ComReleaser.ReleaseCOMObject(oMapDoc); oMapDoc = null; } if (AxMapControl.Map != null) { ComReleaser.ReleaseCOMObject(AxMapControl.Map); AxMapControl.Map = null; } GC.Collect(); GC.WaitForPendingFinalizers(); }
/// <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); } }
private void SaveDoc_Click(object sender, EventArgs e) { string sMxdFileName = axMapControl1.DocumentFilename; IMapDocument pMapDocument = new MapDocumentClass(); if (axMapControl1.LayerCount == 0) { MessageBox.Show("地图文档为空,请先加载地图文档!"); } else { try { pMapDocument.New(sMxdFileName); pMapDocument.ReplaceContents((IMxdContents)axMapControl1.Map as IMxdContents); pMapDocument.Save(pMapDocument.UsesRelativePaths, true); pMapDocument.Close(); MessageBox.Show("保存地图文档成功!"); } catch (Exception ex) { MessageBox.Show("保存地图文档失败!" + ex.ToString()); } } }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { // TODO: Add OpenMxdCommand.OnClick implementation //launch a new OpenFile dialog OpenFileDialog pOpenFileDialog = new OpenFileDialog(); pOpenFileDialog.Filter = "Map Documents (*.mxd)|*.mxd"; pOpenFileDialog.Multiselect = false; pOpenFileDialog.Title = "Open Map Document"; if (pOpenFileDialog.ShowDialog() == DialogResult.OK) { string docName = pOpenFileDialog.FileName; IMapDocument pMapDoc = new MapDocumentClass(); if (pMapDoc.get_IsPresent(docName) && !pMapDoc.get_IsPasswordProtected(docName)) { pMapControl.LoadMxFile(pOpenFileDialog.FileName, null, null); // set the first map as the active view pMapControl.ActiveView.Refresh(); pMapDoc.Close(); } } }
public static void SaveDocumentAs() { try { SaveFileDialog pSaveFileDialog = new SaveFileDialog { Title = "另存为", OverwritePrompt = true, Filter = "ArcMap文档(*.mxd)|*.mxd|ArcMap模板(*.mxt)|*.mxt", RestoreDirectory = true }; if (pSaveFileDialog.ShowDialog() == DialogResult.OK) { string sFilePath = pSaveFileDialog.FileName; IMapDocument pMapDocument = new MapDocumentClass(); pMapDocument.New(sFilePath); pMapDocument.ReplaceContents(Form1.form1.axMapControl1.Map as IMxdContents); pMapDocument.Save(true, true); pMapDocument.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { // TODO: Add OpenNewMapDocument.OnClick implementation //launch a new OpenFile dialog System.Windows.Forms.OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "Map Documents (*.mxd)|*.mxd"; dlg.Multiselect = false; dlg.Title = "Open Map Document"; if (dlg.ShowDialog() == DialogResult.OK) { string docName = dlg.FileName; IMapDocument pMapDoc = new MapDocumentClass(); if (pMapDoc.get_IsPresent(docName) && !pMapDoc.get_IsPasswordProtected(docName)) { // 以下3.3.3.1代码 /* pMapControl.LoadMxFile(dlg.FileName, null, null); * pMapControl.ActiveView.Refresh(); * pMapDoc.Close(); */ // 以下3.3.3.5代码 pMapDoc.Open(docName, string.Empty); IMap map = pMapDoc.get_Map(0); pMapDoc.SetActiveView((IActiveView)map); pControlsSynchronizer.PageLayoutControl.PageLayout = pMapDoc.PageLayout; pControlsSynchronizer.ReplaceMap(map); pMapDoc.Close(); } } }
/// <summary> /// Opens mxd document. /// </summary> /// <param name="sMxdFilePath">The MXD file path.</param> public static void OpenDocument(string sMxdFilePath) { IMapDocument mapDocument = new MapDocumentClass(); if (mapDocument.get_IsPresent(sMxdFilePath) && !mapDocument.get_IsPasswordProtected(sMxdFilePath)) { mapDocument.Open(sMxdFilePath, ""); try { IMap map = mapDocument.get_Map(0); mapDocument.SetActiveView((IActiveView)map); //EnviVars.instance.Synchronizer.PageLayoutControl.PageLayout = mapDocument.PageLayout; //EnviVars.instance.Synchronizer.ReplaceMap(map); EnviVars.instance.MapControl.Map = map; EnviVars.instance.MainForm.Text = sMxdFilePath; } catch (Exception ex) { //_logger.Log(LogLevel.Error, EventType.UserManagement, null, ex); Log.WriteLog(typeof(MapAPI), ex); } finally { mapDocument.Close(); } } }
//另存为地图文档 private void barButtonItem27_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { try { SaveFileDialog pSaveFileDialog = new SaveFileDialog(); pSaveFileDialog.Title = "另存为"; pSaveFileDialog.OverwritePrompt = true; pSaveFileDialog.Filter = "ArcMap文档(*.mxd)|*.mxd|ArcMap模板(*.mxt)|*.mxt"; pSaveFileDialog.RestoreDirectory = true; if (pSaveFileDialog.ShowDialog() == DialogResult.OK) { string sFilePath = pSaveFileDialog.FileName; IMapDocument pMapDocument = new MapDocumentClass(); pMapDocument.New(sFilePath); pMapDocument.ReplaceContents(Variable.pMapFrm.mainMapControl.Map as IMxdContents); pMapDocument.Save(true, true); pMapDocument.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message + "/n" + ex.ToString(), "异常"); } }
protected override void Process(Uri uri) { IMapDocument mapDoc = new MapDocumentClass(); mapDoc.Open(uri.LocalPath, null); try { var documentInfo = (IDocumentInfo2)mapDoc; var title = GetTitle(documentInfo, uri); var subject = GetSubject(documentInfo, uri); var comments = GetComments(documentInfo, uri); var bitmap = GetBitmap(mapDoc); var mxdContent = new MxdContent(title, bitmap, uri, subject, comments); OnFoundContent(mxdContent); } catch (Exception e) { Console.WriteLine(e); } finally { mapDoc.Close(); } }
private void 另存为ToolStripMenuItem_Click(object sender, EventArgs e) { try { SaveFileDialog pSaveFileDialog = new SaveFileDialog(); pSaveFileDialog.Title = "另存为"; pSaveFileDialog.OverwritePrompt = true; pSaveFileDialog.Filter = "ArcMap文档(*.mxd)|*.mxd|ArcMap模板(*.mxt)|*.mxt"; pSaveFileDialog.RestoreDirectory = true; if (pSaveFileDialog.ShowDialog() == DialogResult.OK) { string sFilePath = pSaveFileDialog.FileName; IMapDocument pMapDocument = new MapDocumentClass(); pMapDocument.New(sFilePath); pMapDocument.ReplaceContents(axMapControl1.Map as IMxdContents); pMapDocument.Save(true, true); pMapDocument.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// 工程另存为 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void iSaveProjectAs_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { //ESRI.ArcGIS.SystemUI.ICommand saveCommand = new ControlsSaveAsDocCommand(); //saveCommand.OnCreate(m_mapControl.Object); //saveCommand.OnClick(); IMapDocument pMapDocument = new MapDocumentClass(); SaveFileDialog opensavemxd = new SaveFileDialog(); opensavemxd.Filter = "地图文档(*.mxd)|*.mxd"; //对话框的过滤器 if (opensavemxd.ShowDialog() == DialogResult.OK) { string filePath = opensavemxd.FileName; //获取文件全路径 pMapDocument.New(filePath); IMxdContents pMxdC = m_mapControl.Map as IMxdContents; pMapDocument.ReplaceContents(pMxdC); pMapDocument.Save(true, false); m_mapControl.LoadMxFile(filePath, 0, Type.Missing); //循环遍历所有的地图 for (int i = 0; i < pMapDocument.MapCount; i++) { m_mapControl.Map = pMapDocument.get_Map(i); //绑定地图控件 } pMapDocument.Close(); } }
/// <summary> /// 地图文档保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSaveMap_Click(object sender, EventArgs e) { try { string sMxdFileName = MainMapControl.DocumentFilename; IMapDocument pMapDocument = new MapDocumentClass(); if (sMxdFileName != null && MainMapControl.CheckMxFile(sMxdFileName)) { if (pMapDocument.get_IsReadOnly(sMxdFileName)) { MessageBox.Show("本地图文档是只读,不能保存!"); pMapDocument.Close(); return; } else { SaveFileDialog pSaveFileDialog = new SaveFileDialog(); pSaveFileDialog.Title = "请选择保存路径"; pSaveFileDialog.OverwritePrompt = true; pSaveFileDialog.Filter = "ArcMap文档(*.mxd)|*.mxd|ArcMap模板(*.mxt)|*.mxt"; pSaveFileDialog.RestoreDirectory = true; if (pSaveFileDialog.ShowDialog() == DialogResult.OK) { sMxdFileName = pSaveFileDialog.FileName; } else { return; } } pMapDocument.New(sMxdFileName); pMapDocument.ReplaceContents(MainMapControl.Map as IMxdContents); pMapDocument.Save(pMapDocument.UsesRelativePaths, true); pMapDocument.Close(); MessageBox.Show("保存地图文档成功"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
//保存地图文档 private void barButtonItem26_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { try { string sMxdFileName = Variable.pMapFrm.mainMapControl.DocumentFilename; IMapDocument pMapDocument = new MapDocumentClass(); if (sMxdFileName != null && Variable.pMapFrm.mainMapControl.CheckMxFile(sMxdFileName)) { if (pMapDocument.get_IsReadOnly(sMxdFileName)) { MessageBox.Show("本地图文档是只读的,不能保存!"); pMapDocument.Close(); return; } } else { SaveFileDialog pSaveFileDialog = new SaveFileDialog(); pSaveFileDialog.Title = "请选择保存路径"; pSaveFileDialog.OverwritePrompt = true; pSaveFileDialog.Filter = "ArcMap文档(*.mxd)|*.mxd|ArcMap模板(*.mxt)|*.mxt"; pSaveFileDialog.RestoreDirectory = true; if (pSaveFileDialog.ShowDialog() == DialogResult.OK) { sMxdFileName = pSaveFileDialog.FileName; } else { return; } } pMapDocument.New(sMxdFileName); pMapDocument.ReplaceContents(Variable.pMapFrm.mainMapControl.Map as IMxdContents); pMapDocument.Save(pMapDocument.UsesRelativePaths, true); pMapDocument.Close(); MessageBox.Show("保存地图文档成功!"); } catch (Exception ex) { MessageBox.Show(ex.Message + "/n" + ex.ToString(), "异常"); } }
//地图文档另存为; private void 另存为ToolStripMenuItem_Click(object sender, EventArgs e) { //保存地图文档.mxd try { string smxdfilename = axMapControl1.DocumentFilename; IMapDocument pmapdocument = new MapDocumentClass(); if (smxdfilename != null && axMapControl1.CheckMxFile(smxdfilename)) { if (pmapdocument.get_IsReadOnly(smxdfilename)) { MessageBox.Show("本地图为只读文档,不能修改保存!"); pmapdocument.Close(); return; } } else { saveFileDialog1.Title = "选择保存路径"; saveFileDialog1.OverwritePrompt = true; saveFileDialog1.Filter = "ArcMap文档(*.mxd)|*.mxd"; saveFileDialog1.RestoreDirectory = true; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { smxdfilename = saveFileDialog1.FileName; } else { return; } } pmapdocument.ReplaceContents(axMapControl1.Map as IMxdContents); pmapdocument.New(smxdfilename); pmapdocument.Save(true, true); pmapdocument.Close(); MessageBox.Show("地图保存成功!"); } catch (Exception arr) { MessageBox.Show("错误:" + arr.Message, "提示", MessageBoxButtons.OK); } }
/// <summary> /// Saves mxd document. /// </summary> /// <param name="sMxdFilePath">The MXD file path.</param> public static void SaveDocument(string sMxdFilePath) { if (!string.IsNullOrEmpty(sMxdFilePath) && EnviVars.instance.MapControl.CheckMxFile(sMxdFilePath)) { IMapDocument mapDocument = new MapDocumentClass(); mapDocument.Open(sMxdFilePath, ""); mapDocument.ReplaceContents((IMxdContents)EnviVars.instance.PageLayoutControl.PageLayout); mapDocument.Save(mapDocument.UsesRelativePaths, true); mapDocument.Close(); } }
private void SaveMapDoc() { if (null != m_pagelayoutcontrol.DocumentFilename && m_MapControl.CheckMxFile(m_pagelayoutcontrol.DocumentFilename)) { IMapDocument mapDoc = new MapDocumentClass(); mapDoc.Open(m_pagelayoutcontrol.DocumentFilename, string.Empty); mapDoc.ReplaceContents((IMxdContents)m_pagelayoutcontrol.PageLayout); mapDoc.Save(mapDoc.UsesRelativePaths, false); mapDoc.Close(); } }
/// <summary> /// 清空图层并保存 /// </summary> public void ClearLayers() { IMapDocument pMapDoc = new MapDocumentClass(); string strfilename = AxMapControlMainMap.DocumentFilename; pMapDoc.Open(strfilename, ""); pMapDoc.Map[0].ClearLayers(); pMapDoc.Save(); pMapDoc.Close(); AxMapControlMainMap.LoadMxFile(strfilename); }
protected void OpenAdministrativeMapDoc(string adminMapDoc) { IMapDocument mapDoc = new MapDocumentClass(); if (mapDoc.get_IsPresent(adminMapDoc) && !mapDoc.get_IsPasswordProtected(adminMapDoc)) { mapDoc.Open(adminMapDoc, string.Empty); // set the first map as the active view m_adminMap = mapDoc.get_Map(0); mapDoc.SetActiveView((IActiveView)m_adminMap); mapDoc.Close(); m_mapcontrol.Map = m_adminMap; } }
void IGMap.CloseMxd() { IMapDocument mapDoc = new MapDocumentClass(); mapDoc.Open(this._mapHook.DocumentFilename, string.Empty); mapDoc.Close(); }
void IGMap.SaveMxd() { if (this._mapHook.CheckMxFile(this._mapHook.DocumentFilename)) { //string a=((IMapDocument)this._mapHook).DocumentFilename; //create a new instance of a MapDocument IMapDocument mapDoc = new MapDocumentClass(); mapDoc.Open(this._mapHook.DocumentFilename, string.Empty); //Make sure that the MapDocument is not readonly if (mapDoc.get_IsReadOnly(this._mapHook.DocumentFilename)) { MessageBox.Show("Map document is read only!"); mapDoc.Close(); return; } //Replace its contents with the current map mapDoc.ReplaceContents((IMxdContents)this._mapHook.Map); //save the MapDocument in order to persist it mapDoc.Save(mapDoc.UsesRelativePaths, false); //close the MapDocument mapDoc.Close(); } }
static void Main(string[] args) { bool showHelp = false; bool gzip = false; bool overwrite = false; bool verbose = false; string destination = "."; int[] levels = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }; HashSet<string> fields = null; int threadCount = System.Environment.ProcessorCount; OptionSet p = new OptionSet() { { "d|dir=", "destination directory (defaults to current directory)", d => destination = d }, { "l|levels=", "list of scale levels [0-19], separated by commas", l => levels = l.Split(new char[] { ',' }).Select(s => Convert.ToInt32(s)).ToArray() }, { "f|fields=", "list of field names to include in UTFGrid data", f => fields = new HashSet<string>(f.Split(new char[] { ',' })) }, { "t|threads=", "number of threads to use (defaults to number of processors)", t => threadCount = Convert.ToInt32(t) }, { "z|zip", "zip the json files using gzip compression before saving", z => gzip = z != null }, { "o|overwrite", "overwrite existing files", o => overwrite = o != null }, { "v|verbose", "verbose output", v => verbose = v != null }, { "h|help", "show this message and exit", h => showHelp = h != null } }; List<string> extra; try { extra = p.Parse(args); } catch (OptionException e) { Console.Write("utfgrid"); Console.WriteLine(e.Message); Console.WriteLine("Try `utfgrid --help' for more information."); return; } if (showHelp) { Console.WriteLine("Usage: utfgrid [OPTIONS]+ mxd_document"); Console.WriteLine("Generate UTFGrid files from the given map document"); Console.WriteLine(); Console.WriteLine("Options:"); p.WriteOptionDescriptions(Console.Out); return; } else if (extra.Count < 1) { Console.WriteLine("utfgrid: no map document specified"); Console.WriteLine("Try `utfgrid --help' for more information."); return; } RuntimeManager.BindLicense(ProductCode.EngineOrDesktop); IMap map = null; try { IMapDocument mapDocument = new MapDocumentClass(); mapDocument.Open(extra[0], null); map = mapDocument.ActiveView as IMap; if (map == null) { map = mapDocument.get_Map(0); } mapDocument.Close(); } catch (Exception) { } if (map == null) { Console.WriteLine("Unable to open map at " + extra[0]); return; } if ((map.SpatialReference.FactoryCode != 102113) && (map.SpatialReference.FactoryCode != 102100) && (map.SpatialReference.FactoryCode != 3785)) { Console.WriteLine("Spatial reference of map must be Web Mercator (is " + map.SpatialReference.FactoryCode + ")"); return; } IActiveView activeView = map as IActiveView; // get the extent from the active view IEnvelope fullExtent = activeView.FullExtent; Console.WriteLine("starting utfgrid generator with " + threadCount + " threads"); UTFGridGeneratorConfig config = new UTFGridGeneratorConfig(extra[0], DescribeTiles(levels, activeView.FullExtent)); config.GZip = gzip; config.Overwrite = overwrite; config.Verbose = verbose; config.Destination = destination; Thread[] workerThreads = new Thread[threadCount]; for (int i = 0; i < threadCount; i++) { workerThreads[i] = new Thread(new ParameterizedThreadStart(UTFGridGenerator.Execute)); workerThreads[i].SetApartmentState(ApartmentState.STA); workerThreads[i].IsBackground = true; workerThreads[i].Priority = ThreadPriority.BelowNormal; workerThreads[i].Name = "UTFGridGenerator " + (i + 1).ToString(); workerThreads[i].Start(config); } foreach (Thread t in workerThreads) { t.Join(); } workerThreads = null; }
/// <summary> /// 生成MXD,并将数据库重置 /// </summary> /// <returns></returns> public bool CreateMXD() { try { string strMxdFile = GetMXDFile(); File.Copy(System.Windows.Forms.Application.StartupPath + "\\" + COMMONCONST.RelativePath_MXD +"\\"+ this.StandardName + ".MXD", strMxdFile); IMapDocument mapDoc = new MapDocumentClass(); mapDoc.Open(strMxdFile, null); // 重定向数据库 IMap mapTarget = mapDoc.get_Map(0); Hy.Common.Utility.Esri.AEAccessFactory.ResetMapWorkspace(this.BaseWorkspace, mapTarget); // 修改空间参考及范围 IEnumDataset enDataset = this.BaseWorkspace.get_Datasets(esriDatasetType.esriDTAny); IDataset dataset = enDataset.Next(); double xMin=double.MaxValue, xMax=double.MinValue, yMin=double.MaxValue, yMax=double.MinValue; IEnvelope envExtent = null; ISpatialReference spatialRef = null; while (dataset != null) { IGeoDataset geoDataset = dataset as IGeoDataset; if (geoDataset != null) { //mapTarget.SpatialReference = geoDataset.SpatialReference; //mapDoc.ActiveView.Extent.SpatialReference = geoDataset.SpatialReference; //mapDoc.ActiveView.Extent = geoDataset.Extent; //mapDoc.ActiveView.FullExtent.SpatialReference = geoDataset.SpatialReference; //mapDoc.ActiveView.FullExtent = geoDataset.Extent; spatialRef = geoDataset.SpatialReference; envExtent = geoDataset.Extent; if (!envExtent.IsEmpty) { if (xMin > envExtent.XMin) xMin = envExtent.XMin; if (yMin > envExtent.YMin) yMin = envExtent.YMin; if (xMax < envExtent.XMax) xMax = envExtent.XMax; if (yMax < envExtent.YMax) yMax = envExtent.YMax; } //break; } dataset = enDataset.Next(); } mapTarget.SpatialReference = spatialRef; envExtent.PutCoords(xMin, yMin, xMax, yMax); //mapTarget.RecalcFullExtent(); mapDoc.ActiveView.Extent = envExtent; mapDoc.ActiveView.FullExtent = envExtent; (mapTarget as IActiveView).FullExtent = envExtent; mapDoc.Save(true, false); mapDoc.Close(); // 再复制 “任务执行格式验证.xsd”文件 File.Copy(System.Windows.Forms.Application.StartupPath + "\\" + COMMONCONST.RelativePath_MXD + "\\" + COMMONCONST.File_Name_XSD, GetTaskFolder() + "\\" + COMMONCONST.File_Name_XSD); return true; } catch (Exception exp) { SendMessage(enumMessageType.Exception, "生成MXD失败,错误信息:" + exp.Message); return false; } }
private void menuSaveDoc_Click(object sender, EventArgs e) { //execute Save Document command if (m_mapControl.CheckMxFile(m_mapDocumentName)) { //create a new instance of a MapDocument IMapDocument mapDoc = new MapDocumentClass(); mapDoc.Open(m_mapDocumentName, string.Empty); //Make sure that the MapDocument is not readonly if (mapDoc.get_IsReadOnly(m_mapDocumentName)) { MessageBox.Show("地图文件已经准备完毕!"); mapDoc.Close(); return; } //Replace its contents with the current map mapDoc.ReplaceContents((IMxdContents)m_mapControl.Map); //save the MapDocument in order to persist it mapDoc.Save(mapDoc.UsesRelativePaths, false); //close the MapDocument mapDoc.Close(); } }
public override bool SaveMap(string filePath) { IMapDocument mapDocument = new MapDocumentClass(); if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } mapDocument.New(filePath); mapDocument.ReplaceContents((IMxdContents)this._axMapCtrl.Map); mapDocument.Save(mapDocument.UsesRelativePaths, true); mapDocument.Close(); return true; }
public override bool LoadMap(string filePath) { IMapDocument mapDoc = new MapDocumentClass(); if (mapDoc.get_IsPresent(filePath) && !mapDoc.get_IsPasswordProtected(filePath)) { mapDoc.Open(filePath, string.Empty); // set the first map as the active view IMap map = mapDoc.get_Map(0); mapDoc.SetActiveView((IActiveView)map); this._axLayoutCtrl.PageLayout = mapDoc.PageLayout; this._mapAndLayoutSync.ReplaceMap(map); mapDoc.Close(); this._mapFile = filePath; return true; } else { return false; } /* if (this._axMapCtrl.CheckMxFile(filePath)) { this._axMapCtrl.LoadMxFile(filePath, Type.Missing, Type.Missing); this._axMapCtrl.Enabled = true; this._mapFile = filePath; return true; } else { return false; } */ }
// File menu items void fileToolStripMenuItems_Click(object sender, EventArgs e) { ToolStripMenuItem menuItem = sender as ToolStripMenuItem; if (menuItem == null) return; ICommand command = null; string itemName = menuItem.Name; switch (itemName) { case "newDocToolStripMenuItem": command = new CreateNewDocCmd(); command.OnCreate(m_MapControl.Object); command.OnClick(); break; case "openDocToolStripMenuItem": command = new ControlsOpenDocCommandClass(); command.OnCreate(m_MapControl.Object); command.OnClick(); break; case "saveasStripMenuItem": command = new ControlsSaveAsDocCommandClass(); command.OnCreate(m_MapControl.Object); command.OnClick(); break; case "saveDocToolStripMenuItem": if (m_MapControl.CheckMxFile(m_DocmentFileName)) { IMapDocument mapDoc = new MapDocumentClass(); mapDoc.Open(m_DocmentFileName, string.Empty); if (!mapDoc.get_IsReadOnly(m_DocmentFileName)) { mapDoc.ReplaceContents((IMxdContents)m_MapControl.Map); mapDoc.Save(mapDoc.UsesRelativePaths, false); mapDoc.Close(); } else MessageBox.Show("Cann't be save because of read-only document"); } break; case "exitDocToolStripMenuItem": DialogResult res = MessageBox.Show("Whether to save the current document?", "AOView", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (res == DialogResult.Yes) { command = new ControlsSaveAsDocCommandClass(); command.OnCreate(axMapControl1.Object); command.OnClick(); } Application.Exit(); break; default: break; } }
protected void OpenPastureMapDoc(Pasture pasture) { IMapDocument mapDoc = new MapDocumentClass(); if (mapDoc.get_IsPresent(pasture.strMapDoc) && !mapDoc.get_IsPasswordProtected(pasture.strMapDoc)) { mapDoc.Open(pasture.strMapDoc, string.Empty); // set the first map as the active view m_pastureMap = mapDoc.get_Map(0); mapDoc.SetActiveView((IActiveView)m_pastureMap); mapDoc.Close(); } }
public void FetchLayers(object a) { Status = "Fetching..."; IMapDocument pMapDoc = new MapDocumentClass(); try { pMapDoc.Open(MxdInfo.FullName); IDocumentInfo2 pDocInfo = (IDocumentInfo2)pMapDoc; var map = pMapDoc.get_Map(0); var count = map.LayerCount; for (int i = 0; i < map.LayerCount; i++) { ILayer layer = (ILayer)map.get_Layer(i); try { IDataLayer2 dataLayer = (IDataLayer2)layer; IDatasetName name = (IDatasetName)dataLayer.DataSourceName; IWorkspaceName workspace = name.WorkspaceName; IPropertySet propSet = workspace.ConnectionProperties; object obj1 = new object[1]; object obj2 = new object[1]; propSet.GetAllProperties(out obj1, out obj2); object[] array1 = (object[])obj1; object[] array2 = (object[])obj2; _knownLayers.Add(new LayerEntry(layer.Name, array2[0].ToString(), MxdInfo.Name)); Status = string.Format("Found {0}/{1}", (i + 1), count); FetchLayersEvent(); } catch (Exception e) { _knownLayers.Add(new LayerEntry(layer.Name, "Unknown - not a feature layer", MxdInfo.Name)); Status = string.Format("Found {0}/{1}", (i + 1), count); FetchLayersEvent(); } } } catch (Exception e) { Status = "An error occurred"; } finally { pMapDoc.Close(); FetchLayersEvent(); } }
/// <summary> /// Save document menu event handler /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <remarks>Save the current MapDocument</remarks> private void menuSaveDoc_Click(object sender, System.EventArgs e) { //make sure that the current MapDoc is valid first if (m_documentFileName != string.Empty && m_mapControl.CheckMxFile(m_documentFileName)) { //create a new instance of a MapDocument class IMapDocument mapDoc = new MapDocumentClass(); //Open the current document into the MapDocument mapDoc.Open(m_documentFileName, string.Empty); //Replace the map with the one of the PageLayout mapDoc.ReplaceContents((IMxdContents)m_pageLayoutControl.PageLayout); //save the document mapDoc.Save(mapDoc.UsesRelativePaths, false); mapDoc.Close(); } }