文档对象主要由IMapdocument和IMxdContents接口完成的。IMapDocument定义了操作和管理文档对象的方法和属性,包括读、写和保存一个文档文件(*.mxd)。
public void ReplaceContents (IMxdContents pObject);保存修改;
public void Save ( bool bUseRelativePaths,bool bCreateThumnbail);
public void SaveAs (string sDocument,bool bUseRelativePaths,bool bCreateThumnbail);
IMxdContents接口:Provides access to members to pass data into and out off a MXD map document file. Coclasses that implement this interface can limited the implementation to one property if required.
1 新建一个Mxd空白文档:
string path=@"f:\TEST\untitled.mxd";
MapDocument pMapDocument = new MapDocumentClass();
pMapDocument.New(path);
pMapDocument.Open(path, "");
axMapControl1.Map = pMapDocument.get_Map(0);
2 在打开一个Mxd文档进行修改、编辑再保存在原文件里面:
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.Save(true, true);
3 自定义加载各种数据,也就是一开始就没有Mxd文档,之后进行修改、编辑,把当前地图保存为一个Mxd文档
方法1: SaveFileDialog Sfd = new SaveFileDialog();
Sfd.Title = "另存文档";
Sfd.Filter = "(*.mxd)|*.mxd";
Sfd.ShowDialog();
string path = Sfd.FileName;
IMxdContents pMxdC;
pMxdC = axMapControl1.Map as IMxdContents;
IMapDocument pMapDocument = new MapDocumentClass();
pMapDocument.New(path);
IActiveView pActiveView = axMapControl1.Map as IActiveView;
pMapDocument.ReplaceContents(pMxdC);
public void ReplaceContents (IMxdContents pObject);保存修改;
public void Save ( bool bUseRelativePaths,bool bCreateThumnbail);
public void SaveAs (string sDocument,bool bUseRelativePaths,bool bCreateThumnbail);
IMxdContents接口:Provides access to members to pass data into and out off a MXD map document file. Coclasses that implement this interface can limited the implementation to one property if required.
1 新建一个Mxd空白文档:
string path=@"f:\TEST\untitled.mxd";
MapDocument pMapDocument = new MapDocumentClass();
pMapDocument.New(path);
pMapDocument.Open(path, "");
axMapControl1.Map = pMapDocument.get_Map(0);
2 在打开一个Mxd文档进行修改、编辑再保存在原文件里面:
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.Save(true, true);
3 自定义加载各种数据,也就是一开始就没有Mxd文档,之后进行修改、编辑,把当前地图保存为一个Mxd文档
方法1: SaveFileDialog Sfd = new SaveFileDialog();
Sfd.Title = "另存文档";
Sfd.Filter = "(*.mxd)|*.mxd";
Sfd.ShowDialog();
string path = Sfd.FileName;
IMxdContents pMxdC;
pMxdC = axMapControl1.Map as IMxdContents;
IMapDocument pMapDocument = new MapDocumentClass();
pMapDocument.New(path);
IActiveView pActiveView = axMapControl1.Map as IActiveView;
pMapDocument.ReplaceContents(pMxdC);
pMapDocument.Save(true, true);
方法2:
ICommand command = new ControlsSaveAsDocCommandClass();
command.OnCreate(MapMainView.Object);
command.OnClick();
}
本文介绍了如何使用ArcGIS API中的IMapDocument和IMxdContents接口来创建、修改和保存MXD地图文档。涵盖新建文档、编辑现有文档及将自定义数据保存为MXD文件的方法。
7625

被折叠的 条评论
为什么被折叠?



