GIS设计与开发课程设计(三)

环境:Windows10专业版 + ArcGIS10.2 + ArcEngine10.2 + Visual Studio 2019

因每个人电脑版本和软件版本不同,运行的结果可能不同

系列文章:

GIS设计与开发课程设计(一)

GIS设计与开发课程设计(二)

GIS设计与开发课程设计(三)


目录

三、功能实现

3.16 栅格计算器

3.16.1 实现思想

3.16.2 实现的主体代码及注释

3.17 缓冲区分析

3.17.1 实现思想

3.17.2 实现的主体代码及注释

3.18 叠加分析

3.18.1 实现思想

3.18.2 实现的主体代码及注释

3.19 创建点

3.19.1 实现思想

3.19.2 实现的主体代码及注释

3.20 创建线

3.20.1 实现思想

3.20.2 实现的主体代码及注释

3.21 创建面

3.21.1 实现思想

3.21.2 实现的主体代码及注释

3.22 视图切换

3.22.1 实现思想

3.22.2 实现的主体代码及注释

3.23 插入标题

3.23.1 实现思想

3.23.2 实现的主体代码及注释

3.24 插入指北针

3.24.1 实现思想

3.24.2 实现的主体代码及注释

3.25 插入比例尺

3.25.1 实现思想

3.25.2 实现的主体代码及注释

3.26 插入图例

3.26.1 实现思想

3.26.2 实现的主体代码及注释

四、课程设计的收获与感悟

4.1收获

4.2感悟


三、功能实现

3.16 栅格计算器

3.16.1 实现思想

(1)添加“栅格计算器”控件。

(2)添加“栅格计算器窗口”,并设置好相关布局,为各个按钮生成点击事件响应函数。读取输入的表达式,读入相关数据,并将计算结果输出。

(3)为“栅格计算器”控件生成点击事件响应函数。

3.16.2 实现的主体代码及注释

using System;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.SpatialAnalyst;
using ESRI.ArcGIS.GeoAnalyst;
using System.Collections;
using ESRI.ArcGIS.DataSourcesRaster;
using ESRI.ArcGIS.Geometry;
using System.IO;/// <summary>/// 使mapcontrolMain中的部分图层添加到listBox中/// </summary>/// <param name="bLayer"></param>/// <remarks></remarks>private void PopulateListBoxWithMapLayers(bool bLayer){int i = 0;ILayer pLayer = default(ILayer);listBoxLayer.Items.Clear();for (i = 0; i <= pCurMap.LayerCount - 1; i++){//获取图层名字,并且加到listbox中pLayer = pCurMap.get_Layer(i);if (pLayer.Valid == true){if (bLayer == true){if (pLayer is IRasterLayer){listBoxLayer.Items.Add(pLayer.Name);}}}}}/// <summary>/// 获取指定图层的范围大小/// </summary>/// <returns></returns>/// <remarks></remarks>private IEnvelope GetLayerExtend(string sLayerName){ILayer pLayer = default(ILayer);IEnvelope pEnvelope = default(IEnvelope);int i = 0;pEnvelope = new Envelope() as IEnvelope;for (i = 0; i <= pCurMap.LayerCount - 1; i++){pLayer = pCurMap.get_Layer(i);if (pLayer.Name == sLayerName.ToString()){if (pLayer.Valid == true){//获取分析范围的Envelope对象pEnvelope = pLayer.AreaOfInterest;}}}return pEnvelope;}/// <summary>/// 该函数获得栅格影像分辨率大小/// </summary>/// <param name="sLayerName"></param>/// <returns></returns>/// <remarks></remarks>private double GetRasterCellSize(string sLayerName){double dCellSize = 0;int i = 0;ILayer pLyr = default(ILayer);IRasterLayer pRlyr = default(IRasterLayer);IRaster pRaster = default(IRaster);IRasterProps pRasterProp = default(IRasterProps);double cellX;double cellY;for (i = 0; i <= pCurMap.LayerCount - 1; i++){pLyr = pCurMap.get_Layer(i);if ((pLyr != null)){if (pLyr is IRasterLayer){if (pLyr.Name == sLayerName){pRlyr = (IRasterLayer)pLyr;pRaster = pRlyr.Raster;pRasterProp = (IRasterProps)pRaster;cellX = pRasterProp.MeanCellSize().X;cellY = pRasterProp.MeanCellSize().Y;dCellSize = (cellX + cellY) / 2.0;}}}}return dCellSize;}/// <summary>/// 通过名称在MAP中找到图层/// </summary>/// <param name="pMap"></param>/// <param name="sName"></param>/// <returns></returns>/// <remarks></remarks>private ILayer FindLayerByName(IMap pMap, string sName){int i = 0;ILayer pSelectedLayer = null;for (i = 0; i <= pMap.LayerCount - 1; i++){if (pMap.get_Layer(i).Name == sName){pSelectedLayer = pMap.get_Layer(i);break; // TODO: might not be correct. Was : Exit For}}return pSelectedLayer;}#region "栅格运算"/// <summary>/// 在listBox中选择某一个数据名称,双击,该数据名称添加到计算器文本框中/// </summary>/// <param name="sender"></param>/// <param name="e"></param>/// <remarks></remarks>private void listBoxLayer_DoubleClick(object sender, System.EventArgs e){txtCalculate.SelectedText = "[" + listBoxLayer.SelectedItem.ToString() + "]";string tmpstr = listBoxLayer.SelectedItem.ToString();bool blnItm = false;int i;for (i = 0; i < LayerList.Count; i++){if (LayerList[i].ToString() == tmpstr){blnItm = true;}}if (blnItm == false){LayerList.Add(listBoxLayer.SelectedItem.ToString());}for (i = 0; i < LayerList.Count; i++){MessageBox.Show(LayerList[i].ToString());}}private void btnCalculate_Click(System.Object sender, System.EventArgs e){IRasterLayer pRasLayer = default(IRasterLayer);IRaster pRaster = default(IRaster);IEnvelope layExtend = default(IEnvelope);double AnalysisExtentLeft = 0;double AnalysisExtentRight = 0;double AnalysisExtentTop = 0;double AnalysisExtentBottom = 0;string layerNameFir = null;try{if (LayerList.Count != 0){if (txtResultFullName.Text.ToString().Length != 0){layerNameFir = LayerList[0].ToString();layExtend = GetLayerExtend(layerNameFir);AnalysisExtentLeft = layExtend.XMin;AnalysisExtentRight = layExtend.XMax;AnalysisExtentTop = layExtend.YMax;AnalysisExtentBottom = layExtend.YMin;pMapAlgebraOp = new RasterMapAlgebraOp() as IMapAlgebraOp;//设置栅格计算分析环境IRasterAnalysisEnvironment pRasAnaEnv = default(IRasterAnalysisEnvironment);pRasAnaEnv = (IRasterAnalysisEnvironment)pMapAlgebraOp;pRasAnaEnv.VerifyType = esriRasterVerifyEnum.esriRasterVerifyOn;object dddd;dddd = GetRasterCellSize(layerNameFir);pRasAnaEnv.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref dddd);//设置分析范围pAnaExtentIEnvelope pAnaExtent = default(IEnvelope);pAnaExtent = new Envelope() as IEnvelope;pAnaExtent.XMin = System.Convert.ToDouble(AnalysisExtentLeft);pAnaExtent.XMax = System.Convert.ToDouble(AnalysisExtentRight);pAnaExtent.YMax = System.Convert.ToDouble(AnalysisExtentTop);pAnaExtent.YMin = System.Convert.ToDouble(AnalysisExtentBottom);object dd1 = pAnaExtent;object dd2 = null;pRasAnaEnv.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref dd1, ref dd2);foreach (string LayerName in LayerList){pRasLayer = (IRasterLayer)FindLayerByName(pCurMap, LayerName);//MsgBox(LayerName)pRaster = pRasLayer.Raster;RasterList.Add(pRaster);}//将容量设置为 ArrayList 中元素的实际数目LayerList.TrimToSize();RasterList.TrimToSize();//绑定int i = 0;if (LayerList.Count == RasterList.Count){for (i = 0; i <= LayerList.Count - 1; i++){pMapAlgebraOp.BindRaster((IGeoDataset)RasterList[i], LayerList[i].ToString());}}//获取文本框中的运算表达式()string sCalExpression = null;sCalExpression = txtCalculate.Text;//执行地图代数运算IRaster pOutRasterDS = default(IRaster);pOutRasterDS = (IRaster)pMapAlgebraOp.Execute(sCalExpression);//解除绑定if (LayerList.Count == RasterList.Count){for (i = 0; i <= LayerList.Count - 1; i++){pMapAlgebraOp.UnbindRaster(LayerList[i].ToString());}}//保存到工作空间IWorkspaceFactory pWsFact = default(IWorkspaceFactory);IWorkspace pWS = default(IWorkspace);int hwnd = 0;pWsFact = new RasterWorkspaceFactory();pWS = pWsFact.OpenFromFile(sOutRasPath, hwnd);IRasterBandCollection pRasterbandCollection = default(IRasterBandCollection);pRasterbandCollection = (IRasterBandCollection)pOutRasterDS;IDataset pDataset = default(IDataset);pDataset = pRasterbandCollection.SaveAs(sOutRasName, pWS, "IMAGINE Image");//输出到mapcontrol中IRasterDataset pOutResultDS = default(IRasterDataset);pOutResultDS = (IRasterDataset)pDataset;IRasterLayer pOutRasterLayer = default(IRasterLayer);pOutRasterLayer = new RasterLayer();pOutRasterLayer.CreateFromDataset(pOutResultDS);//MapControlMain.AddLayer(pOutRasterLayer)pCurMap.AddLayer(pOutRasterLayer);this.Close();}else{MessageBox.Show("保存计算结果为空,请输入结果文件名!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);}}}catch (Exception ex){MessageBox.Show(ex.ToString());//Interaction.MsgBox(ex.ToString);}}#endregion#region "保存栅格运算后的结果"private void btnSaveResult_Click(System.Object sender, System.EventArgs e){string pOutDSName = null;int iOutIndex = 0;var _with1 = SaveFileDialog1;_with1.Title = "保存栅格运算结果";_with1.Filter = "(*.img)|*.img";_with1.OverwritePrompt = false;_with1.InitialDirectory = Application.StartupPath;if (_with1.ShowDialog() == System.Windows.Forms.DialogResult.OK){pOutDSName = _with1.FileName;FileInfo fFile = new FileInfo(pOutDSName);//判断文件名是否已经存在,如果存在,则弹出提示if (fFile.Exists == true){MessageBox.Show("文件名已存在,请重新输入", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);txtResultFullName.Text = "";}else{iOutIndex = pOutDSName.LastIndexOf("\\");sOutRasPath = pOutDSName.Substring(0, iOutIndex + 1);sOutRasName = pOutDSName.Substring(iOutIndex + 1, pOutDSName.Length - iOutIndex - 1);txtResultFullName.Text = pOutDSName;}}}//栅格计算器private void miRasterCalculator_Click(object sender, EventArgs e){FrmRasterCalculatornew frmRstCalDlg = new FrmRasterCalculatornew(this, axMapControl1.Map);frmRstCalDlg.Show();}

3.17 缓冲区分析

3.17.1 实现思想

(1)添加“缓冲区分析”控件。

(2)添加“地图分析”类,调用Buffer()函数进行缓冲区查询。

(3)为“缓冲区分析”控件生成点击事件响应函数。

3.17.2 实现的主体代码及注释

using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.esriSystem;//缓冲区查询public bool Buffer(string layerName, string sWhere, int iSize, IMap iMap){//根据过滤条件获取城市名称为北京的城市要素的几何IFeatureClass featClass;IFeature feature;IGeometry iGeom;DataOperator dataOperator = new DataOperator(iMap);IFeatureLayer featLayer = (IFeatureLayer)dataOperator.GetLayerByName(layerName);featClass = featLayer.FeatureClass;IQueryFilter queryFilter = new QueryFilter();queryFilter.WhereClause = sWhere;//设置过滤条件IFeatureCursor featCursor;featCursor = (IFeatureCursor)featClass.Search(queryFilter, false);int count = featClass.FeatureCount(queryFilter);feature = featCursor.NextFeature();iGeom = feature.Shape;//设置空间的缓冲区作为空间查询的几何范围ITopologicalOperator ipTO = (ITopologicalOperator)iGeom;IGeometry iGeomBuffer = ipTO.Buffer(iSize);//根据缓冲区几何对城市图层进行空间过滤ISpatialFilter spatialFilter = new SpatialFilter();spatialFilter.Geometry = iGeomBuffer;spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIndexIntersects;//定义要素选择对象,以要素搜索图层进行实例化IFeatureSelection featSelect = (IFeatureSelection)featLayer;//以空间过滤器对要素进行选择,并建立新选择集featSelect.SelectFeatures(spatialFilter, esriSelectionResultEnum.esriSelectionResultNew, false);return true;}//缓冲区查询private void miBuffer_Click(object sender, EventArgs e){MapAnalysis mapAnalysis = new MapAnalysis();mapAnalysis.Buffer("World Cities", "CITY_NAME='Beijing'", 1, axMapControl1.Map);IActiveView activeView;activeView = axMapControl1.ActiveView;activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, 0, axMapControl1.Extent);}

3.18 叠加分析

3.18.1 实现思想

(1)添加“叠加分析”控件。

(2)添加“叠加分析”窗口,设置相应布局和控件,为控件生成点击事件响应函数,选择“裁剪或者相交叠加分析”,若选择“裁剪”,利用BasicGeoprocessorClass.Clip()方法进行裁剪分析,若选择“相交”,利用BasicGeoprocessorClass.Intersect()方法进行相交分析。

(3)为“叠加分析”控件生成点击事件响应函数。

3.18.2 实现的主体代码及注释

using System;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.DataSourcesFile;namespace GISAE
{public partial class OverlayAnalysis : Form{//定义全局变量public IMap pMap { get; set; }public AxMapControl axMapControl1 { get; set; }public OverlayAnalysis(ESRI.ArcGIS.Controls.AxMapControl basicControl){InitializeComponent();axMapControl1 = basicControl;}//窗体加载事件private void OverlayAnalysis_Load(object sender, EventArgs e){try{pMap = axMapControl1.Map;if (pMap == null)return;//清空comboboxcbInputDataset.Items.Clear();cbOverlayDataset.Items.Clear();string layerName;   //用于储存图层名字for (int i = 0; i < pMap.LayerCount; i++){layerName = pMap.Layer[i].Name;cbInputDataset.Items.Add(layerName);cbOverlayDataset.Items.Add(layerName);}cbOverlayWays.Items.Add("裁剪");cbOverlayWays.Items.Add("相交");cbOverlayWays.SelectedIndex = 0;}catch (Exception ex){MessageBox.Show(ex.Message);}}private ILayer GetLayerByName(IMap pMap, string layerName){ILayer pLayer = null;ILayer tempLayer = null;try{for (int i = 0; i < pMap.LayerCount; i++){tempLayer = pMap.Layer[i];if (tempLayer.Name.ToUpper() == layerName.ToUpper())      //判断名字大写是否一致{pLayer = tempLayer;break;}}}catch (Exception ex){MessageBox.Show(ex.Message);}return pLayer;}private void OK_Click(object sender, EventArgs e){if (pMap == null)return;//获取数据集ILayer inputDataset = GetLayerByName(pMap, cbInputDataset.Text.Trim());ILayer clipDataset = GetLayerByName(pMap, cbOverlayDataset.Text.Trim());//裁剪if (inputDataset != null && clipDataset != null && cbOverlayWays.Text == "裁剪"){IFeatureLayer inputLayer = inputDataset as IFeatureLayer;IFeatureLayer clipLayer = clipDataset as IFeatureLayer;IBasicGeoprocessor bGP = new BasicGeoprocessorClass();bGP.SpatialReference = pMap.SpatialReference;   //设置空间参考IFeatureClassName pOutput = new FeatureClassNameClass();    //创建FeatureClassNameClass对象,用于获取输入数据集的一些基本信息pOutput.FeatureType = inputLayer.FeatureClass.FeatureType;pOutput.ShapeFieldName = inputLayer.FeatureClass.ShapeFieldName;pOutput.ShapeType = inputLayer.FeatureClass.ShapeType;//利用IDataset获得IWorkspaceNamestring fileDirectory = System.IO.Path.GetDirectoryName(tbOutputPath.Text.Trim());string fileName = System.IO.Path.GetFileName(tbOutputPath.Text.Trim());IWorkspaceFactory pWsFc = new ShapefileWorkspaceFactoryClass();IWorkspace pWs = pWsFc.OpenFromFile(fileDirectory, 0);  //创建一个工作空间对象IDataset pDataset = pWs as IDataset;IWorkspaceName pWsN = pDataset.FullName as IWorkspaceName;  //获取工作空间的信息(获取输出路径)IDatasetName pDatasetName = pOutput as IDatasetName;    //获取或设置数据集中成员的名称信息pDatasetName.Name = fileName;   //设置数据集中的数据成员的名字pDatasetName.WorkspaceName = pWsN;  //设置输出的工作空间(输出路径)//利用裁剪方法来进行叠加分析IFeatureClass featureClass = bGP.Clip(inputLayer.FeatureClass as ITable, false, clipLayer.FeatureClass as ITable, false, 0.01, pOutput);if (featureClass != null){IFeatureLayer featLayer = new FeatureLayerClass();featLayer.FeatureClass = featureClass;featLayer.Name = featureClass.AliasName;//将结果添加到控件中axMapControl1.AddLayer(featLayer);axMapControl1.Refresh();}}//相交if (inputDataset != null && clipDataset != null && cbOverlayWays.Text == "相交"){IFeatureLayer inputLayer = inputDataset as IFeatureLayer;IFeatureLayer clipLayer = clipDataset as IFeatureLayer;IBasicGeoprocessor bGP = new BasicGeoprocessorClass();bGP.SpatialReference = pMap.SpatialReference;   // 设置空间参考IFeatureClassName pOutput = new FeatureClassNameClass();    // 创建FeatureClassNameClass对象,用于获取输入数据集的一些基本信息pOutput.FeatureType = inputLayer.FeatureClass.FeatureType;pOutput.ShapeFieldName = inputLayer.FeatureClass.ShapeFieldName;pOutput.ShapeType = inputLayer.FeatureClass.ShapeType;// 利用IDataset获得IWorkspaceNamestring fileDirectory = System.IO.Path.GetDirectoryName(tbOutputPath.Text.Trim());string fileName = System.IO.Path.GetFileName(tbOutputPath.Text.Trim());IWorkspaceFactory pWsFc = new ShapefileWorkspaceFactoryClass();IWorkspace pWs = pWsFc.OpenFromFile(fileDirectory, 0);  // 创建一个工作空间对象IDataset pDataset = pWs as IDataset;IWorkspaceName pWsN = pDataset.FullName as IWorkspaceName;  // 获取工作空间的信息(获取输出路径)IDatasetName pDatasetName = pOutput as IDatasetName;    // 获取或设置数据集中成员的名称信息pDatasetName.Name = fileName;   // 设置数据集中的数据成员的名字pDatasetName.WorkspaceName = pWsN;  // 设置输出的工作空间(输出路径)// 利用相交方法来进行叠加分析IFeatureClass featureClass = bGP.Intersect(inputLayer.FeatureClass as ITable, false, clipLayer.FeatureClass as ITable, false, 0.01, pOutput);if (featureClass != null){IFeatureLayer featLayer = new FeatureLayerClass();featLayer.FeatureClass = featureClass;featLayer.Name = featureClass.AliasName;// 将结果添加到控件中axMapControl1.AddLayer(featLayer);axMapControl1.Refresh();}}}private void Cancel_Click(object sender, EventArgs e){this.Close();}private void btOutputPath_Click(object sender, EventArgs e){SaveFileDialog flg = new SaveFileDialog();flg.Title = "保存路径";flg.Filter = "ShpFile(*shp)|*.shp";flg.ShowDialog();tbOutputPath.Text = flg.FileName;}}
}//叠加分析private void btnOverlayAnalysis_Click(object sender, EventArgs e){OverlayAnalysis overlayAnalysis = new OverlayAnalysis(axMapControl1);overlayAnalysis.ShowDialog();}

3.19 创建点

3.19.1 实现思想

(1)添加“创建点”控件。

(2)添加“创建点”类,利用DrawPoint()方法画点。

(3)为“创建点”控件生成点击事件响应函数。

3.19.2 实现的主体代码及注释

public DrawPoint(){//// TODO: Define values for the public properties//base.m_category = ""; //localizable text base.m_caption = "";  //localizable text base.m_message = "";  //localizable textbase.m_toolTip = "";  //localizable textbase.m_name = "";   //unique id, non-localizable (e.g. "MyCategory_MyTool")try{//// TODO: change resource name if necessary//string bitmapResourceName = GetType().Name + ".bmp";base.m_bitmap = new Bitmap(GetType(), bitmapResourceName);base.m_cursor = new System.Windows.Forms.Cursor(GetType(), GetType().Name + ".cur");}catch (Exception ex){System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap");}}//创建点private void miCreatePoint_Click(object sender, EventArgs e){ICommand command = new DrawPointTool.DrawPoint();command.OnCreate(axMapControl1.Object);axMapControl1.CurrentTool = command as ITool;}

3.20 创建线

3.20.1 实现思想

(1)添加“创建线”控件。

(2)添加“创建线”类,利用DrawPolylineTool()方法画线。

(3)为“创建线”控件生成点击事件响应函数。

3.20.2 实现的主体代码及注释

            public DrawPolylineTool(){//// TODO: Define values for the public properties//base.m_category = ""; //localizable text base.m_caption = "";  //localizable text base.m_message = "";  //localizable textbase.m_toolTip = "";  //localizable textbase.m_name = "";   //unique id, non-localizable (e.g. "MyCategory_MyTool")try{//// TODO: change resource name if necessary//string bitmapResourceName = GetType().Name + ".bmp";base.m_bitmap = new Bitmap(GetType(), bitmapResourceName);base.m_cursor = new System.Windows.Forms.Cursor(GetType(), GetType().Name + ".cur");}catch (Exception ex){System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap");}}//创建线private void miCreatePolyline_Click(object sender, EventArgs e){ICommand command = new DrawPolyline.DrawPolylineTool();command.OnCreate(axMapControl1.Object);axMapControl1.CurrentTool = command as ITool;}

3.21 创建面

3.21.1 实现思想

(1)添加“创建多边形”控件。

(2)添加“创建多边形”类,利用DrawPolygonTool()方法画线。

(3)为“创建多边形”控件生成点击事件响应函数。

3.21.2 实现的主体代码及注释

public DrawPolygonTool(){//// TODO: Define values for the public properties//base.m_category = ""; //localizable text base.m_caption = "";  //localizable text base.m_message = "";  //localizable textbase.m_toolTip = "";  //localizable textbase.m_name = "";   //unique id, non-localizable (e.g. "MyCategory_MyTool")try{//// TODO: change resource name if necessary//string bitmapResourceName = GetType().Name + ".bmp";base.m_bitmap = new Bitmap(GetType(), bitmapResourceName);base.m_cursor = new System.Windows.Forms.Cursor(GetType(), GetType().Name + ".cur");}catch (Exception ex){System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap");}}//创建多边形private void miCreatePolygon_Click(object sender, EventArgs e){ICommand command = new DrawPolygonTool();command.OnCreate(axMapControl1.Object);axMapControl1.CurrentTool = command as ITool;}

3.22 视图切换

3.22.1 实现思想

(1)创建“显示地图”和“显示页面布局”控件。

(2)为“显示地图”和“显示页面布局”按钮生成点击事件响应函数,并在此函数实现页面切换功能,并用copyToPageLayout()实现页面联动。

3.22.2 实现的主体代码及注释

        //显示地图private void miMap_Click(object sender, EventArgs e){if (miMap.Checked == false){axToolbarControl1.SetBuddyControl(axMapControl1.Object);axTOCControl1.SetBuddyControl(axMapControl1.Object);axMapControl1.Show();axPageLayoutControl1.Hide();miMap.Checked = true;miPageLayout.Checked = false;miPrint.Enabled = false;}else{axToolbarControl1.SetBuddyControl(axPageLayoutControl1.Object);axTOCControl1.SetBuddyControl(axPageLayoutControl1.Object);axMapControl1.Hide();axPageLayoutControl1.Show();miMap.Checked = false;miPageLayout.Checked = true;miPrint.Enabled = true;}}//显示页面布局private void miPageLayout_Click(object sender, EventArgs e){if (miPageLayout.Checked == false){axToolbarControl1.SetBuddyControl(axPageLayoutControl1.Object);axTOCControl1.SetBuddyControl(axPageLayoutControl1.Object);axPageLayoutControl1.Show();axMapControl1.Hide();miPageLayout.Checked = true;miMap.Checked = false;miPrint.Enabled = true;}else{axToolbarControl1.SetBuddyControl(axMapControl1.Object);axTOCControl1.SetBuddyControl(axMapControl1.Object);axPageLayoutControl1.Hide();axMapControl1.Show();miPageLayout.Checked = false;miMap.Enabled = true;miPrint.Enabled = false;}}public void copyToPageLayout(){IObjectCopy objectCopy = new ObjectCopy();//对象拷贝接口object copyFromMap = axMapControl1.Map;//地图对象object copyMap = objectCopy.Copy(copyFromMap);//将axMapControl1的地图对象拷贝object copyToMap = axPageLayoutControl1.ActiveView.FocusMap;//axPageLayoutControl1活动视图中的地图objectCopy.Overwrite(copyMap, ref copyToMap);//将axMapControl1地图对象覆盖axPageLayout1当前地图}private void axMapControl1_OnMapReplaced(object sender, IMapControlEvents2_OnMapReplacedEvent e){IMap pMap;pMap = axMapControl1.Map;for (int i = 0; i < pMap.LayerCount; i++){axMapControl2.Map.AddLayer(pMap.get_Layer(i));}//使鹰眼视图中显示加载地图的全图axMapControl2.Extent = axMapControl2.FullExtent;copyToPageLayout();}private void axMapControl1_OnAfterScreenDraw(object sender, IMapControlEvents2_OnAfterScreenDrawEvent e){IActiveView activeView = (IActiveView)axPageLayoutControl1.ActiveView.FocusMap;//axPageLayoutControl1的活动视图的地图IDisplayTransformation displayTransformation = activeView.ScreenDisplay.DisplayTransformation;//活动视图的屏幕显示的显示信息displayTransformation.VisibleBounds = axMapControl1.Extent;//将axMapControl1的范围赋值给axPageLayoutControl1的范围axPageLayoutControl1.ActiveView.Refresh();//刷新axPageLayoutControl1的活动视图copyToPageLayout();//将axMapControl1的地图拷贝到axPageLayoutControl1中}

3.23 插入标题

3.23.1 实现思想

(1)创建“插入标题”控件。

(2)为“插入标题”按钮生成点击事件响应函数,调用AddTitle()函数实现插入标题。

3.23.2 实现的主体代码及注释

        //插入标题private void miAddTittle_Click(object sender, EventArgs e){string str = Interaction.InputBox("请输入图名", "提示", "示例地图", -1, -1);AddTitle(axPageLayoutControl1.PageLayout, str);}public void AddTitle(IPageLayout pageLayout, String s){//找到PageLayoutIPageLayout pPageLayout = axPageLayoutControl1.PageLayout;//找到元素容器IGraphicsContainer pGraphicsContainer = pPageLayout as IGraphicsContainer;//创建元素ITextElement pTextElement = new TextElementClass();pTextElement.Text = s;ITextSymbol pTextSymbol = new TextSymbolClass();//Text的符号样式pTextSymbol.Font.Name = "宋体";IRgbColor pColor = new RgbColorClass();pColor.Blue = 255;pColor.Red = 255;pColor.Green = 0;pTextSymbol.Size = 30;pTextSymbol.Color = pColor;pTextSymbol.Font.Bold = true;pTextElement.Symbol = pTextSymbol;//设置位置                        IElement pElement = pTextElement as IElement;pElement.Geometry = axPageLayoutControl1.TrackRectangle();//将元素添加到容器中pGraphicsContainer.AddElement(pElement, 0);//刷新axPageLayoutControl1.Refresh();}

3.24 插入指北针

3.24.1 实现思想

(1)创建“插入指北针”控件。

(2)为“插入标题”按钮生成点击事件响应函数,调用AddElement()函数插入指北针元素。

3.24.2 实现的主体代码及注释

        //插入指北针private void miAddNorthArrows_Click(object sender, EventArgs e){//获取axPageLayoutControl1的图形容器IGraphicsContainer graphicsContainer = axPageLayoutControl1.GraphicsContainer;//获取axPageLayoutControl1空间里面显示的地图图层IMapFrame mapFrame = (IMapFrame)graphicsContainer.FindFrame(axPageLayoutControl1.ActiveView.FocusMap);UID uID = new UIDClass();uID.Value = "esriCore.MarkerNorthArrow";if (mapFrame == null) return;IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uID, null);if (mapSurroundFrame == null) return;IEnvelope envelope = new EnvelopeClass();envelope.PutCoords(1000, 1000, 18, 25);IElement element = (IElement)mapSurroundFrame;element.Geometry = envelope;mapSurroundFrame.MapSurround.Name = "MarkerNorthArrow";INorthArrow pNorthArrow = mapSurroundFrame.MapSurround as INorthArrow;axPageLayoutControl1.AddElement(element, Type.Missing, Type.Missing, "MarkerNorthArrow", 0);axPageLayoutControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);}

3.25 插入比例尺

3.25.1 实现思想

(1)创建“插入比例尺”控件。

(2)创建“ScaleBarTool”类,设置比例尺的相关属性,调用AddElement()函数插入比例尺元素。

(3)为“插入比例尺”按钮生成点击事件响应函数。

3.25.2 实现的主体代码及注释

using System;
using System.Windows.Forms;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geometry;namespace GISAE
{class ScaleBarTool{public static int count = 0;public void AddSacleBar(AxPageLayoutControl axPageLayoutControl1, IEnvelope pEnv, int strBarType = 0){if (count > 0)return;IScaleBar pScaleBar;IMapFrame pMapFrame;IMapSurroundFrame pMapSurroundFrame;IMapSurround pMapSurround;IElementProperties pElementPro;//产生一个UID对象,使用它产生不同的MapSurround对象UID pUID = new UIDClass();pUID.Value = " esriCarto.scalebar";IPageLayout pPageLayout;pPageLayout = axPageLayoutControl1.PageLayout;IGraphicsContainer pGraphicscontainer;pGraphicscontainer = pPageLayout as IGraphicsContainer;IActiveView pActiveView;pActiveView = pGraphicscontainer as IActiveView;IMap pMap;pMap = pActiveView.FocusMap;//获得与地图相关的MapFramepMapFrame = pGraphicscontainer.FindFrame(pMap) as IMapFrame;pMapSurroundFrame = pMapFrame.CreateSurroundFrame(pUID, null);//依据传入参数不同使用不同类型的比例尺//MessageBox.Show(strBarType.ToString());switch (strBarType){case 0:pScaleBar = new AlternatingScaleBarClass();//西安交互式比例尺                  break;case 1:pScaleBar = new DoubleAlternatingScaleBarClass();//双线交互比例尺break;case 2:pScaleBar = new HollowScaleBarClass();//中空式比例尺break;case 3:pScaleBar = new ScaleLineClass();//线式比例尺break;case 4:pScaleBar = new SingleDivisionScaleBarClass();//分割式比例尺break;case 5:pScaleBar = new SteppedScaleLineClass();//阶梯式比例尺break;default:pScaleBar = new ScaleLineClass();break;}pScaleBar.Division = 5;pScaleBar.Divisions = 5;pScaleBar.LabelGap = 5;pScaleBar.LabelPosition = esriVertPosEnum.esriAbove;pScaleBar.Map = pMap;pScaleBar.Name = "myscaleBar";pScaleBar.Subdivisions = 3;pScaleBar.UnitLabel = "千米";pScaleBar.UnitLabelGap = 5;pScaleBar.UnitLabelPosition = esriScaleBarPos.esriScaleBarAbove;pScaleBar.Units = esriUnits.esriKilometers;pMapSurround = pScaleBar;pMapSurroundFrame.MapSurround = pMapSurround;pElementPro = pMapSurroundFrame as IElementProperties;pElementPro.Name = "my scalebar";//将MapSurroundFrame对象添加到控件中                                axPageLayoutControl1.AddElement(pMapSurroundFrame as IElement, pEnv, Type.Missing, Type.Missing, 0);pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);}}
}//插入比例尺private void miAddScaleBar_Click(object sender, EventArgs e){ScaleBarTool scaleBarTool = new ScaleBarTool();IEnvelope pEnv = new EnvelopeClass();pEnv.PutCoords(20, 3, 10, 2);scaleBarTool.AddSacleBar(axPageLayoutControl1, pEnv, 0);}

3.26 插入图例

3.26.1 实现思想

(1)创建“插入图例”控件。

(2)为“插入比例尺”按钮生成点击事件响应函数,调用AddElement()函数插入比例尺元素。

3.26.2 实现的主体代码及注释

        //插入图例private void miAddLegend_Click(object sender, EventArgs e){//获取axPageLayoutControl1的图形容器IGraphicsContainer graphicsContainer = axPageLayoutControl1.GraphicsContainer;//获取axPageLayoutControl1空间里面显示的地图图层IMapFrame mapFrame = (IMapFrame)graphicsContainer.FindFrame(axPageLayoutControl1.ActiveView.FocusMap);if (mapFrame == null) return;//创建图例UID uID = new UIDClass();//创建UID作为该图例的唯一标识符,方便创建之后进行删除、移动等操作uID.Value = "esriCarto.Legend";IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uID, null);if (mapSurroundFrame == null) return;if (mapSurroundFrame.MapSurround == null) return;mapSurroundFrame.MapSurround.Name = "Legend";IEnvelope envelope = new EnvelopeClass();envelope.PutCoords(1, 3, 20, 8);//设置图例摆放位置(原点在axPageLayoutControl左下角)IElement element = (IElement)mapSurroundFrame;element.Geometry = envelope;//将图例转化为几何要素添加到axPageLayoutControl1,并刷新页面显示axPageLayoutControl1.AddElement(element, Type.Missing, Type.Missing, "图例", 0);axPageLayoutControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);}

四、课程设计的收获与感悟

4.1收获

首先,通过这门课程设计,我学会了如何使用 ArcEngine 10.2 这一强大的 GIS 开发工具。我学会了①鹰眼、空间书签、数据列表显示、创建 shapefile 文件与编辑要素;②文件(新建地图文档、打开地图文档、保存、另存为、添加数据(添加.shp、添加.lyr、添加栅格数据、退出));③栅格数据处理功能(获取栅格目录、创建栅格数据集、添加栅格数据、格式转换、影像镶嵌、栅格数据计算器(由用户定义计算表达式));④空间分析功能,包括据缓冲区分析、叠加分析、裁剪分析(要求采用对话框方式实现,通过对话框选择数据对象与相应的设置);⑤几何对象的绘制(点绘制、线绘制、面绘制)并保存到指定图层;⑥视图切换(页面视图、数据视图)且实现两者的数据联动;⑦制图(插入标题、插入指北针、插入比例尺、插入图例、文字编辑)。

其次,这门课程设计让我对地理信息系统的应用有了更深入的了解。我学会了如何利用GIS技术进行地理数据的采集、处理和分析。我了解了如何使用ArcEngine的工具和功能来进行地理数据的查询、空间分析和栅格数据分析等,这些技能对于解决实际的地理问题和进行地理决策具有重要的意义。

此外,这门课程设计还培养了我得到交流能力。在课程设计中,与同学们一起讨论Bug,并解决这些问题,并提高了自己的沟通和组织能力。

最后,这门课程设计为我未来的工作发展打下了坚实的基础。面向对象,软件工程的思想,让我对开发流程更为熟悉。GIS技术在许多领域都有广泛的应用,包括城市规划、环境保护、农业和物流等。通过学习GIS设计与开发,我具备了一定的开发和应用GIS技术的能力,这对于从事与GIS开发相关的工作或研究具有重要的竞争优势。

4.2感悟

完成课程设计后,我深深感悟到地理信息系统的无限可能和广泛应用的重要性。通过这门课程设计,我对地理信息的价值和作用有了更深入的理解。首先,我意识到地理信息系统在解决实际问题和支持决策方面的巨大潜力。GIS技术可以帮助我们收集、管理和分析大量的地理数据,从而揭示地理现象的模式和趋势。无论是城市规划、环境保护还是农业生产,都可以通过地理信息系统来优化决策过程,提高效率和效果。这种对地理信息的深入应用,使我对GIS技术的重要性有了更深刻的认识。

最重要的是,这门课程设计让我意识到学习是一个持续不断的过程。GIS技术不断发展和更新,新的工具和方法不断涌现。我意识到需要不断学习和保持更新的知识,以适应快速变化的技术环境。这让我明白到,只有不断学习和提升自己,才能不断适应新的需求和挑战。

总而言之,完成课程设计让我对地理信息系统有了更深入的认识和体会。我明白了地理信息系统在实际问题解决和决策支持中的重要性,体验了同学交流合作的力量,也意识到学习的持续性和重要性。这些感悟将成为我在未来学术和职业发展中的重要指导,帮助我不断进步和取得更大的成就。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/bicheng/30103.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Apple Watch开发入门知识,还是很有必要的

随着现在 Apple 生态圈的发展&#xff0c;越来越多的 App 会把自己的简化版从 iOS 迁移至 WatchOS&#xff08;支付宝、微信、手Q、头条、QQ音乐、网易云音乐等等&#xff0c;都有Watch版App&#xff09;。官方开发文档&#xff1a;Setting up a watchOS project | Apple Devel…

学习Java中的日志系统设计与优化

学习Java中的日志系统设计与优化 大家好&#xff0c;我是免费搭建查券返利机器人省钱赚佣金就用微赚淘客系统3.0的小编&#xff0c;也是冬天不穿秋裤&#xff0c;天冷也要风度的程序猿&#xff01; 引言 在Java应用程序中&#xff0c;日志系统是非常重要的组成部分&#xff…

力扣1539.第k个缺失的正整数

力扣1539.第k个缺失的正整数 占位运算 只要n<k &#xff0c;k;最终k就是结果 class Solution {public:int findKthPositive(vector<int>& arr, int k) {for(int n : arr){if(n < k) k ;else break;}return k;}};

神经网络学习3-卷积层

膨胀卷积&#xff0c;也被称为空洞卷积或扩张卷积&#xff0c;是一种特殊的卷积运算&#xff0c;它在标准卷积的基础上引入了一个额外的超参数&#xff0c;即膨胀率&#xff08;dilation rate&#xff09;。这个超参数决定了在卷积核的元素之间插入多少额外的空间。通过这种方式…

04-对原生app应用中的元素进行定位

本文介绍对于安卓原生app应用中的元素如何进行定位。 一、uiautomatorviewer uiautomatorviewer是Android-SDK自带的一个元素定位工具&#xff0c;非常简单好用&#xff0c;可以使用该工具查看app应用中的元素属性&#xff0c;帮助我们在代码中进行元素定位。 1&#xff09;使…

为什么要用较短的域名?

在互联网的世界中&#xff0c;域名是网站身份的重要标识。一个好记、易于输入的域名对于网站的成功至关重要。在众多域名中&#xff0c;较短的域名因其独特的优势而受到青睐。本文将探讨为什么要选择较短的域名&#xff0c;并分析其带来的益处。 易记性 优势&#xff1a;较短…

黑龙江游戏行业需不需要做等保?

游戏行业是否需要进行等保 游戏行业作为当今最受欢迎的娱乐方式之一&#xff0c;其用户数量庞大且用户粘性强&#xff0c;因此成为了网络安全攻击的重点目标。为了保障游戏行业的网络安全&#xff0c;等级保护制度&#xff08;简称“等保”&#xff09;的实施显得尤为重要。 …

el-table 固定前n行 配合 max-height 生效

:row-class-name"TableRowClassName" 加上类名 <el-table:data"computedTableList"borderstyle"width: 100%":row-class-name"TableRowClassName"max-height"800"><el-table-column fixed prop"name"…

【OS基础】符合AUTOSAR标准的RTAOS-Alarms详解

目录 前言 正文 7.报警Alarms 7.1配置Alarms 7.1.1激活一个任务 7.1.2 设置一个事件 7.1.3报警回调Alarm Callback 7.1.4 增加计数器值 7.2设置Alarms 7.2.1 绝对Alarms 7.2.2 相对Alarm 7.3自启动Alarms 7.4 删除Alarms 7.5确认何时会发生Alarm 7.6非周期Alarm…

CC攻击需要成本吗

CC攻击几乎不需要成本。这是因为CC攻击很容易发起&#xff0c;大部分进行CC攻击的人都是使用在网上下载的工具&#xff0c;这些工具很少去伪造特征&#xff0c;因此会留下一些痕迹。这意味着&#xff0c;尽管CC攻击可能会对目标系统造成严重影响&#xff0c;但其发起者几乎不需…

Josephus问题

Josephus问题&#xff0c;又称为“约瑟夫环”或“丢手绢问题”&#xff0c;是一个经典的计算机科学和数学问题。这个问题的起源有一个古老的故事背景&#xff0c;但与解决问题的具体算法设计并无直接关联。以下是Josephus问题的详细描述和一种可能的解决方案&#xff1a; ### …

细致解析跨境电商多平台搭建利器-179海关接口源码应用方法

介绍 跨境电商已成为当前电商行业的热门发展方向之一。为满足跨境电商的需求&#xff0c;各大平台纷纷推出了多平台搭建利器。其中&#xff0c;179海关接口源码是一款非常实用的工具&#xff0c;本文将对其应用方法进行细致解析。 了解179海关接口源码 179海关接口源码可以帮…

Vue插件开发:Vue.js的插件架构允许开发者扩展Vue的核心功能,我们可以探讨如何开发一个Vue插件并与社区分享

了解Vue插件 Vue插件的概念: Vue插件用于为Vue.js添加全局级别的功能。它提供了一种开箱即用的机制来应用全局性的功能扩展。这些插件通常用来将全局方法或属性,组件选项,Vue实例的方法,或者注入一些组件选项比如mixins和自定义方法添加至Vue.js。 Vue插件的使用场景:…

2024最新版Vcpkg安装第三方库报错error: building XXXX failed with: BUILD_FAILED

很多朋友用Vcpkg安装第三方库的时候基本都会遇到报错的情况&#xff0c;而且大部分都会出现下面这个页面里面的红色报错信息&#xff0c;但是实际上真正错误应该是上面的Cmake Error提示&#xff0c;下面的红色警告只是Vcpkg官方提供给我们的一个最基础的解决方式&#xff0c;而…

mvn dependency:tree查看依赖树时,报错:No plugin found for prefix ‘dependency’ 该如何解决

今天引入依赖出来问题&#xff0c;就像查看依赖树找找&#xff0c;结果依赖树也不行&#xff0c;好吧&#xff0c;又多了个bug任务。从字面英文意思来看就是没有安装相关的查看依赖树的插件&#xff0c;其实也就是这么简单。&#xff08;我的SpringBoot版本是2.6.3&#xff09;…

【杂记-浅谈数据的封装与解封装】

一、数据封装 概述 Encapsulation&#xff0c;数据封装&#xff0c;是计算机网络中的一个核心概念&#xff0c;涉及将数据从一个地方传输到另一个地方的过程。封装不仅包括数据的传输&#xff0c;还包括一系列的处理步骤&#xff0c;以确保数据能够准确无误地到达目的地。这一…

【Docker系列】深入解析 Docker 容器部署脚本

&#x1f49d;&#x1f49d;&#x1f49d;欢迎来到我的博客&#xff0c;很高兴能够在这里和您见面&#xff01;希望您在这里可以感受到一份轻松愉快的氛围&#xff0c;不仅可以获得有趣的内容和知识&#xff0c;也可以畅所欲言、分享您的想法和见解。 推荐:kwan 的首页,持续学…

【稳定检索/投稿优惠】2024年生物技术与食品科学国际会议(ICBFS 2024)

2024 International Conference on Biotechnology and Food Science 2024年生物技术与食品科学国际会议 【会议信息】 会议简称&#xff1a;ICBFS 2024 大会时间&#xff1a;点击查看 截稿时间&#xff1a;点击查看 大会地点&#xff1a;中国厦门 会议官网&#xff1a;www.icb…

汇聚荣优势是什么?

汇聚荣优势是什么?在探讨企业成功之道时&#xff0c;我们不得不提及“汇聚荣优势”这一概念。简而言之&#xff0c;它指的是企业通过整合内外部资源&#xff0c;形成独特的竞争优势&#xff0c;以实现持续发展与市场领先地位的战略行为。这种优势的构建不是一蹴而就的&#xf…

生信网络学院|06月21日《SolidWorks Costing助力制造企业建立成本核算体系》

课程主题&#xff1a;SolidWorks Costing助力制造企业建立成本核算体系 课程时间&#xff1a;2024年06月21日 14:00-14:30 主讲人&#xff1a;张丹清 生信科技 售前顾问 Costing成本分析简介钣金件成本分析加工件成本分析装配体成本分析总结&答疑 安装腾讯会议客户端或…