public void ModifyMxd(IFeatureClass outFeatureClass, double[] scales, ISpatialReference spatialReference) { var fi = new FileInfo("animation.mxd"); IMapDocument mapDocument = new MapDocumentClass(); mapDocument.Open(fi.FullName); IMap map = mapDocument.Map[0]; ILayer layerToDelete = null; while ((layerToDelete = map.Layers.Next()) != null) { map.DeleteLayer(layerToDelete); } mapDocument.Save(); mapDocument.Map[0].SpatialReference = spatialReference; mapDocument.Save(); foreach (double scale in scales) { ILayer layer = new FeatureLayerClass(); layer.Name = $"scale{scale}"; layer.SpatialReference = spatialReference; layer.MaximumScale = scale - 1; layer.MinimumScale = scale + 1; ((IFeatureLayer)layer).FeatureClass = outFeatureClass; ISimpleRenderer renderer = new SimpleRendererClass() { Symbol = new SimpleLineSymbolClass() { Color = new RgbColorClass() { Red = 0, Green = 0, Blue = 255 }, } }; ((IGeoFeatureLayer)layer).Renderer = renderer as IFeatureRenderer; mapDocument.Map[0].AddLayer(layer); mapDocument.Save(); } mapDocument.Save(); var mlc = map.LayerCount; var lc = mapDocument.Map[0].LayerCount; ;; //var mlc = map.LayerCount; //var mdmlc = mapDocument.Map[0].LayerCount; //mapDocument.SaveAs($"map{DateTime.Now.ToBinary()}.mxd"); ; }
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 保存SToolStripMenuItem_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; IMxdContents pMxdcontents = axMapControl1.Map as IMxdContents; pMapDocument.New(saveFileName); pMapDocument.ReplaceContents(pMxdcontents); if (pMapDocument.get_IsReadOnly(saveFileName)) { MessageBox.Show("本地图文档只读的,不能保存!"); } else { pMapDocument.Save(pMapDocument.UsesRelativePaths, true); MessageBox.Show("保存地图文档成功!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
/// <summary> /// 地图文档编辑过后进行保存 /// </summary> private void Save_Click(object sender, EventArgs e) { //获取pMapDocument对象 IMxdContents pMxdC; pMxdC = axMapControl1.Map as IMxdContents; IMapDocument pMapDocument = new MapDocumentClass(); pMapDocument.Open(axMapControl1.DocumentFilename, ""); IActiveView pActiveView = axMapControl1.Map as IActiveView; pMapDocument.ReplaceContents(pMxdC); //判断pMapDocument是否为空 if (pMapDocument == null) { return; } //检查地图文档是否是只读 if (pMapDocument.get_IsReadOnly(pMapDocument.DocumentFilename) == true) { MessageBox.Show("本地图文档是只读的,不能保存!"); return; } //根据相对的路径保存地图文档 pMapDocument.Save(pMapDocument.UsesRelativePaths, true); }
/// <summary> /// 保存mxd文档 /// mapControl为地图控件的名称 /// 日期2013-12-13 /// lntu_GISer1 /// </summary> public void SaveMxdFile(AxMapControl mapControl) { IMxdContents pMxdC; pMxdC = mapControl.ActiveView.FocusMap as IMxdContents; IMapDocument pMapDocument = new MapDocumentClass(); if (mapControl.DocumentFilename != null) { pMapDocument.Open(mapControl.DocumentFilename, ""); pMapDocument.ReplaceContents(pMxdC); if (pMapDocument.get_IsReadOnly(pMapDocument.DocumentFilename)) { MessageBox.Show("当前地图文档为只读文档!"); return; } try { pMapDocument.Save(true, true); MessageBox.Show("地图文档保存成功!"); } catch (Exception e) { MessageBox.Show(e.Message); } } //用当前的文件路径设置保存文件 }
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(); } }
//另存为 public static void SaveDocAs(AxMapControl mapControl, AxPageLayoutControl pageLayoutControl = null) { IMapDocument pMapDocument = new MapDocumentClass(); SaveFileDialog saveDlg = new SaveFileDialog(); saveDlg.Title = "地图文档另存为"; saveDlg.Filter = "mxd文件|*.mxd|所有文件(添加后缀名)|*.*"; saveDlg.ShowDialog(); string strDocFileN = saveDlg.FileName; if (strDocFileN == string.Empty) { return; } pMapDocument.Open(mapControl.DocumentFilename); if (strDocFileN == mapControl.DocumentFilename) { pMapDocument.Save(pMapDocument.UsesRelativePaths, true); return; } else { pMapDocument.SaveAs(strDocFileN, true, true); MessageBox.Show("保存成功!", "信息提示"); } }
//保存地图文档 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(); } }
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(); }
//另存为地图文档 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(), "异常"); } }
public static string[] CloneMaps(int numCopies, string mxdPath) { List <string> maps = new List <string>(); string testPath = Path.Combine(Path.GetDirectoryName(mxdPath), "TestMaps"); if (System.IO.Directory.Exists(testPath)) { System.IO.Directory.Delete(testPath, true); } IMapDocument srcMap = new MapDocumentClass(); srcMap.Open(mxdPath); srcMap.Save(false); Marshal.FinalReleaseComObject(srcMap); System.IO.Directory.CreateDirectory(testPath); for (int i = 0; i < numCopies; i++) { const string fmt = "_{0:0000}.mxd"; string mapName = Path.GetFileNameWithoutExtension(mxdPath) + string.Format(fmt, i + 1); string mapPath = Path.Combine(testPath, mapName); System.IO.File.Copy(mxdPath, mapPath); maps.Add(mapPath); } return(maps.ToArray()); }
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 另存为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); } }
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> /// 工程另存为 /// </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(); } }
private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)//保存mxd文档 { IMxdContents pMxdC = null; try { pMxdC = axMapControl1.Map as IMxdContents; IMapDocument pMapDocument = new MapDocumentClass(); if (axMapControl1.DocumentFilename == null) { XtraMessageBox.Show("地图文档不存在,需新建"); SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "地图文档(*.mxd)|*.mxd"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { pMapDocument.New(saveFileDialog.FileName); } else { return; } } else { pMapDocument.Open(axMapControl1.DocumentFilename, ""); } pMapDocument.ReplaceContents(pMxdC); pMapDocument.Save(true, true); XtraMessageBox.Show("保存成功"); } catch { } }
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 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(); } }
/// <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); } }
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); } }
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); } }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { if (!ModMxd._MxdPath.Equals("")) { DialogResult pResult = MessageBox.Show("是否保存当前的地图文档?", "询问", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); switch (pResult) { case DialogResult.Cancel: return; case DialogResult.Yes: { IMxdContents pMxdC; pMxdC = m_hookHelper.FocusMap as IMxdContents; IMapDocument pMapDocument = new MapDocumentClass(); //打开地图文档 if (File.Exists(ModMxd._MxdPath)) { pMapDocument.Open(ModMxd._MxdPath, ""); } else { pMapDocument.New(ModMxd._MxdPath); } //保存信息 IActiveView pActiveView = m_hookHelper.ActiveView; pMapDocument.ReplaceContents(pMxdC); pMapDocument.Save(true, true); break; } case DialogResult.No: break; } } OpenFileDialog pOpendlg = new OpenFileDialog(); pOpendlg.Title = "打开地图文档"; pOpendlg.Filter = "(*.mxd)|*.mxd"; if (pOpendlg.ShowDialog() != DialogResult.OK) { return; } string strMxdName = pOpendlg.FileName; if (m_AxMapControl.CheckMxFile(strMxdName)) { m_AxMapControl.LoadMxFile(strMxdName, "", ""); } ModMxd._MxdPath = strMxdName; }
/// <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); }
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 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 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> /// 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(); } }
/// <summary> /// 保存 mxd 文件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void 保存ToolStripMenuItem_Click(Object sender, EventArgs e) { IMxdContents pMxdC; pMxdC = axMapControl1.Map as IMxdContents; IMapDocument pMapDocument = new MapDocumentClass(); pMapDocument.Open(axMapControl1.DocumentFilename, ""); pMapDocument.ReplaceContents(pMxdC); pMapDocument.Save(true, true); }
private void menuSaveDoc_Click(object sender, EventArgs e) { 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(); } }
public override void OnClick() { //保存路径 if (ModMxd._MxdPath.Equals("")) { SaveFileDialog Sfd = new SaveFileDialog(); Sfd.Title = "另存为地图文档"; Sfd.Filter = "(*.mxd)|*.mxd"; if (Sfd.ShowDialog() != DialogResult.OK) { return; } ModMxd._MxdPath = Sfd.FileName; } IMxdContents pMxdC; pMxdC = _AppHk.MapControl.Map as IMxdContents; IMapDocument pMapDocument = new MapDocumentClass(); //打开地图文档 if (File.Exists(ModMxd._MxdPath)) { pMapDocument.Open(ModMxd._MxdPath, ""); } else { pMapDocument.New(ModMxd._MxdPath); } //保存信息 IActiveView pActiveView = _AppHk.MapControl.Map as IActiveView; pMapDocument.ReplaceContents(pMxdC); try//yjl20110817 防止保存时,其他程序也在打开这个文档而导致共享冲突从而使系统报错 { pMapDocument.Save(true, true); if (this.WriteLog) { Plugin.LogTable.Writelog("保存地图文档到" + ModMxd._MxdPath); } ErrorHandle.ShowFrmErrorHandle("提示", "保存成功!"); } catch (Exception ex) { ErrorHandle.ShowFrmErrorHandle("提示", "保存失败!请关掉其他正在打开该文档的程序,重新试一次。"); } pMapDocument.Close();//yjl20110817 }
/// <summary> /// 确定之后将文档进行默认保存 /// </summary> /// <param name="mapControlDefault">当前视图mapcontrol</param> /// <returns></returns> public static bool SaveInMxd(IMapControlDefault mapControlDefault) { IMxdContents pMxdContents; pMxdContents = mapControlDefault.Map as IMxdContents; IMapDocument pMapDocument = new MapDocumentClass(); pMapDocument.Open(mapControlDefault.DocumentFilename, ""); pMapDocument.ReplaceContents(pMxdContents); try { pMapDocument.Save(true, true); return true; } catch { //MessageBox.Show("当前的文档文件发生共享冲突!请关闭其他打开该文档的应用。", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return false; } }
/// <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; } }
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; }
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(); } }
// 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; } }
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(); } }
/// <summary> /// /// </summary> private void saveMapDocument(AxMapControl pAxMapControl) { IMxdContents pMxdC; pMxdC = pAxMapControl.Map as IMxdContents; IMapDocument pMapDocument = new MapDocumentClass(); pMapDocument.Open(pAxMapControl.DocumentFilename, ""); IActiveView pActiveView = pAxMapControl.Map as IActiveView; pMapDocument.ReplaceContents(pMxdC); if (pMapDocument == null) return; //检查地图文档是否是只读 if (pMapDocument.get_IsReadOnly(pMapDocument.DocumentFilename) == true) { MessageBox.Show("本地图文档是只读的,不能保存!"); return; } //根据相对的路径保存地图文档 pMapDocument.Save(pMapDocument.UsesRelativePaths, true); MessageBox.Show("地图文档保存成功!"); }
public static void SaveDocument2(AxMapControl axMapControl1) { try { //判断pMapDocument是否为空, //获取pMapDocument对象 IMxdContents pMxdC; pMxdC = axMapControl1.Map as IMxdContents; IMapDocument pMapDocument = new MapDocumentClass(); pMapDocument.Open(axMapControl1.DocumentFilename, ""); IActiveView pActiveView = axMapControl1.Map as IActiveView; pMapDocument.ReplaceContents(pMxdC); if (pMapDocument == null) return; //检查地图文档是否是只读 if (pMapDocument.get_IsReadOnly(pMapDocument.DocumentFilename) == true) { MessageBox.Show("本地图文档是只读的,不能保存!"); return; } //根据相对的路径保存地图文档 pMapDocument.Save(pMapDocument.UsesRelativePaths, true); MessageBox.Show("地图文档保存成功!"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <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(); } }