资源预览内容
第1页 / 共53页
第2页 / 共53页
第3页 / 共53页
第4页 / 共53页
第5页 / 共53页
第6页 / 共53页
第7页 / 共53页
第8页 / 共53页
第9页 / 共53页
第10页 / 共53页
亲,该文档总共53页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
using System;using System.IO;using System.Windows.Forms;using ESRI.ArcGIS.Carto;using ESRI.ArcGIS.Controls;using ESRI.ArcGIS.DataSourcesFile;using ESRI.ArcGIS.DataSourcesGDB;using ESRI.ArcGIS.DataSourcesRaster;using ESRI.ArcGIS.Display;using ESRI.ArcGIS.esriSystem;using ESRI.ArcGIS.Geodatabase;using ESRI.ArcGIS.Geometry;using ESRI.ArcGIS.SystemUI;namespace MapOperationpublic partial class FormMain : Form#region 变量定义/地图导出窗体private FormExportMap frmExpMap = null;/长度、面积量算private FormMeasureResult frmMeasureResult = null; /量算结果窗体private INewLineFeedback pNewLineFeedback; /追踪线对象private INewPolygonFeedback pNewPolygonFeedback; /追踪面对象private IPoint pPointPt = null; /鼠标点击点private IPoint pMovePt = null; /鼠标移动时的当前点private double dToltalLength = 0; /量测总长度private double dSegmentLength = 0; /片段距离private IPointCollection pAreaPointCol = new MultipointClass() ; /面积量算时画的点进行存储; private string sMapUnits = 未知单位; /地图单位变量private object missing = Type.Missing; /TOC菜单IFeatureLayer pTocFeatureLayer = null; /点击的要素图层private FormAtrribute frmAttribute = null; /图层属性窗体private ILayer pMoveLayer; /需要调整显示顺序的图层private int toIndex; /存放拖动图层移动到的索引号 /鹰眼同步private bool bCanDrag; /鹰眼地图上的矩形框可移动的标志private IPoint pMoveRectPoint; /记录在移动鹰眼地图上的矩形框时鼠标的位置private IEnvelope pEnv; /记录数据视图的Extent#endregion#region 初始化public FormMain()InitializeComponent();axTOCControl.SetBuddyControl(mainMapControl);EagleEyeMapControl.Extent = mainMapControl.FullExtent;pEnv = EagleEyeMapControl.Extent;DrawRectangle(pEnv);#endregion#region 数据加载 #region LoadMxFile方法加载地图文档文件private void btnLoadMxFile_Click(object sender, EventArgs e)/加载数据前如果有数据则清空tryOpenFileDialog pOpenFileDialog = new OpenFileDialog();pOpenFileDialog.CheckFileExists = true;pOpenFileDialog.Title = 打开地图文档;pOpenFileDialog.Filter = ArcMap文档(*.mxd)|*.mxd;|ArcMap模板(*.mxt)|*.mxt|发布地图文件(*.pmf)|*.pmf|所有地图格式(*.mxd;*.mxt;*.pmf)|*.mxd;*.mxt;*.pmf;pOpenFileDialog.Multiselect = false; /不允许多个文件同时选择pOpenFileDialog.RestoreDirectory = true; /存储打开的文件路径if (pOpenFileDialog.ShowDialog() = DialogResult.OK)string pFileName = pOpenFileDialog.FileName;if (pFileName = )return;if (mainMapControl.CheckMxFile(pFileName) /检查地图文档有效性ClearAllData();mainMapControl.LoadMxFile(pFileName);elseMessageBox.Show(pFileName + 是无效的地图文档!, 信息提示);return;catch (Exception ex) MessageBox.Show(打开地图文档失败 + ex.Message);#endregion#region IMapDocument方法加载Mxd文档文件private void btnIMapDocument_Click(object sender, EventArgs e)tryOpenFileDialog pOpenFileDialog = new OpenFileDialog();pOpenFileDialog.CheckFileExists = true;pOpenFileDialog.Title = 打开地图文档;pOpenFileDialog.Filter = ArcMap文档(*.mxd)|*.mxd;|ArcMap模板(*.mxt)|*.mxt|发布地图文件(*.pmf)|*.pmf|所有地图格式(*.mxd;*.mxt;*.pmf)|*.mxd;*.mxt;*.pmf;pOpenFileDialog.Multiselect = false;pOpenFileDialog.RestoreDirectory = true;if (pOpenFileDialog.ShowDialog() = DialogResult.OK)string pFileName = pOpenFileDialog.FileName;if (pFileName = )return;if (mainMapControl.CheckMxFile(pFileName) /检查地图文档有效性/将数据载入pMapDocument并与Map控件关联IMapDocument pMapDocument = new MapDocument();/using ESRI.ArcGIS.Carto;pMapDocument.Open(pFileName, );/获取Map中激活的地图文档mainMapControl.Map = pMapDocument.ActiveView.FocusMap;mainMapControl.ActiveView.Refresh();else MessageBox.Show(pFileName + 是无效的地图文档!, 信息提示);return;catch (Exception ex)MessageBox.Show(打开地图文档失败 + ex.Message);#endregion#region ControlsOpenDocCommandClass加载地图private void btncontrolsOpenDocCommandClass_Click(object sender, EventArgs e)ICommand command = new ControlsOpenDocCommandClass();command.OnCreate(mainMapControl.Object);command.OnClick();#endregion#region 加载Shape文件private void btnAddShapefile_Click(object sender, EventArgs e)/ClearAllData();tryOpenFileDialog pOpenFileDialog = new OpenFileDialog();pOpenFileDialog.CheckFileExists = true;pOpenFileDialog.Title = 打开Shape文件;pOpenFileDialog.Filter = Shape文件(*.shp)|*.shp;pOpenFileDialog.ShowDialog();/获取文件路径/FileInfo pFileInfo = new FileInfo(pOpenFileDialog.FileName); /string pPath = pOpenFileDialog.FileName.Substring(0, pOpenFileDialog.FileName.Length - pFileInfo.Name.Length);/mainMapControl.AddShapeFile(pPath, pFileInfo.Name);IWorkspaceFactory pWorkspaceFactory;IFeatureWorkspace pFeatureWorkspace;IFeatureLayer pFeatureLayer;string pFullPath = pOpenFileDialog.FileName;if (pFullPath = ) return;int pIndex = pFullPath.LastIndexOf();string pFilePath = pFullPath.Substring(0, pIndex); /文件路径string pFileName = pFullPath.Substring(pIndex + 1); /文件名/实例化ShapefileWorkspaceFactory工作空间,打开Shape文件pWorkspaceFactory = new ShapefileWorkspaceFactory();pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(pFilePath, 0);/创建并实例化要素集IFeatureClass pFeatureClass
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号