目录
打开文件:
OpenFileDialog openMXD = new OpenFileDialog();
openMXD.Title = "打开地图";
openMXD.InitialDirectory = "E:\\大三上学期实验\\ARCGIS Engine\\实验二(及以上)二次开发\\使用控件创建第一个应用程序\\bin\\Debug\\Map";
openMXD.Filter = "Map Documents(*.mxd)|*.mxd";
if (openMXD.ShowDialog() == DialogResult.OK)
{
string MxdPath = openMXD.FileName;
axMapControl1.LoadMxFile(MxdPath);
}
保存文件:
try
{
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);
MessageBox.Show("保存成功!");
}
catch (Exception ex)
{
throw ex;
}
另存为:
OpenFileDialog iOpenFileDialog = new OpenFileDialog();
iOpenFileDialog.Filter = "地图文档(*.mxd)|*.mxd";
if (iOpenFileDialog.ShowDialog() == DialogResult.OK)
{
string iFilePath = iOpenFileDialog.FileName;
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.SaveAs(iFilePath, true, true);
}
导出地图:
try
{
SaveFileDialog pSaveDialog = new SaveFileDialog();
pSaveDialog.FileName = "";
pSaveDialog.Filter = "JPG图片(*.JPG)|*.jpg|tif图片(*.tif)|*.tif|PDF文档(*.PDF)|*.pdf";
if (pSaveDialog.ShowDialog() == DialogResult.OK)
{
double iScreenDispalyResolution = axPageLayoutControl1.ActiveView.ScreenDisplay.DisplayTransformation.Resolution;// 获取屏幕分辨率的值
IExporter pExporter = null;
if (pSaveDialog.FilterIndex == 1)
{
pExporter = new JpegExporterClass();
}
else if (pSaveDialog.FilterIndex == 2)
{
pExporter = new TiffExporterClass();
}
else if (pSaveDialog.FilterIndex == 3)
{
pExporter = new PDFExporterClass();
}
pExporter.ExportFileName = pSaveDialog.FileName;
pExporter.Resolution = (short)iScreenDispalyResolution; //分辨率
tagRECT deviceRect = axPageLayoutControl1.ActiveView.ScreenDisplay.DisplayTransformation.get_DeviceFrame();
IEnvelope pDeviceEnvelope = new EnvelopeClass();
pDeviceEnvelope.PutCoords(deviceRect.left, deviceRect.bottom, deviceRect.right, deviceRect.top);
pExporter.PixelBounds = pDeviceEnvelope; // 输出图片的范围
ITrackCancel pCancle = new CancelTrackerClass();//可用ESC键取消操作
axPageLayoutControl1.ActiveView.Output(pExporter.StartExporting(), pExporter.Resolution, ref deviceRect, axPageLayoutControl1.ActiveView.Extent, pCancle);
Application.DoEvents();
pExporter.FinishExporting();
MessageBox.Show("导出成功!");
}
}
catch (Exception Err)
{
MessageBox.Show(Err.Message, "输出图片", MessageBoxButtons.OK, MessageBoxIcon.Information);
}