1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > ArcGIS二次开发基础教程(03):保存文档和导出地图

ArcGIS二次开发基础教程(03):保存文档和导出地图

时间:2019-12-16 05:28:02

相关推荐

ArcGIS二次开发基础教程(03):保存文档和导出地图

ArcGIS二次开发基础教程(03):保存文档和导出地图

保存文档

保存:

//这里的path为全局变量 在打开文件获添加数据时赋值原路径//判断打开文件是否为mxd文件 是则保存 不是则另存为if(System.IO.File.Exists(path.Remove(path.IndexOf('.')) + ".mxd")){//对于已打开的mxd文档保存在原路径//获取mapcontrol中的地图数据IMXDContexts context = axMapControl.Map as IMXDContexts;IMapDocument mapDocumnet = new MapDocumnetClass();mapDocument.Open(path);mapDocument.ReplaceContexts(context);mapDocument.Save();}else{SaveAs();}

另存为

void SaveAs(){//没有mxd文档的新建一个saveFileDialog.Title = "保存文件";saveFileDialog.Filter = "ArcMap Document(*.mxd)|*.mxd";if(saveFileDialog.ShowDialog()==DialogResult.OK){IMXDContexts context = axMapControl.Map as IMXDContexts;IMapDocument mapDocumnet = new MapDocumnetClass();mapDocument.New(path);mapDocument.ReplaceContexts(context);mapDocument.Save();}}

导出地图

//将mapcontrol的显示范围导出为图片saveFileDialog.Title = "导出图片";//还有其他图片格式同理saveFileDialog.Filter = "JPEG(*.jpg)|*.jpg|PNG(*.png)|*.png|PDF(*.pdf)|*.pdf|BMP(*.bmp)|*.bmp|TIFF(*.tif)|*.tif";if(saveFileDialog.ShowDialog()==DialogResult.OK){IExport export = new ExportAllClass();string path = saveFileDialog.FileName;string extension = System.IO.Path.GetExtenion(path).Replace(".","").ToLower();switch(extension){case "jpg":export = new ExportJPEGClass();break;case "png":export = new ExportPNGClass();break;case "pdf":export = new ExportPDFClass();break;case "bmp":export = new ExportBMPClass();break;case "tif":export = new ExportTIFFClass();break;default:MessageBox.Show("Error");return;}if(ExportImage(export,axMapConrol1.ActiveView,fileName)){MessageBox.Show("Succeed");}else{MessageBox.Show("Error");}}//这里是参考的帮助文档bool ExportImage(IExport export,IActiveView activeView,string fileName){export.ExportFileName = fileName;// Microsoft Windows default DPI resolutionexport.Resolution = 96;// mapcontrol的显示范围tagRECT exportRECT = activeView.ExportFrame;IEnvelope envelope = new EnvelopeClass();envelope.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);export.PixelBounds = envelope;Int32 hDC = export.StartExporting();activeView.Output(hDC, (Int16)export.Resolution, ref exportRECT, null, null);// Finish writing the export file and cleanup any intermediate filesexport.FinishExporting();export.Cleanup();return true;}

历届GIS应用技能大赛开发题答案点这里,尚在不定期更新中

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。