基于GIS的二次开发

功能说明:
针对基础部分和三维数据库建设部分实习内容,进行校园二、三维地理信息系统设计,完成校园地理信息系统二、三维数据库设计和实现,并完成简单的查询、浏览和分析功能。本次实习开发语言为C#,开发平台为vs2010。
界面设计:
在本次实习中,新建的程序项目为窗体型,在窗体中拖入控件MenuStrip、ToolbarControl、StatusStrip、SplitContainer、TabControl、MapControl、PageLayoutControl 等控件,并设置其相关的Dock 属性、Name 和Text属性等,然后进行页面绑定,并添加相应的ArcGISD的工具,本次开发整体页面布局如下:
在这里插入图片描述
1.菜单的添加及其实现
添加菜单,并在其属性面板中设置 Name 属性,然后实现相关菜单,双击事件按钮打到“ Load ”事件并双击,添加此事件,其中新建文件、打开文件、加载数据、关闭文件等部分代码如下:
private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
{ //文件路径名称,包含文件名称和路径名称
string strName = null;
//定义OpenFileDialog,获取并打开地图文档
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Title = “打开MXD”;
openFileDialog.Filter = “MXD文件(.mxd)|.mxd”;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{ strName = openFileDialog.FileName;
if (strName != “”)
{ this.axMapControl1.LoadMxFile(strName); } }
this.axMapControl1.Extent = this.axMapControl1.FullExtent;
}
private void AddData_Click(object sender, EventArgs e)
{ //添加数据
int currentLayerCount = this.axMapControl1.LayerCount;
ICommand pCommand = new ControlsAddDataCommandClass();
pCommand.OnCreate(this.axMapControl1.Object);
pCommand.OnClick(); }
private void Save_Click(object sender, EventArgs e)
{ if (null != m_pageLayoutControl.DocumentFilename&& m_mapControl.CheckMxFile(m_page
LayoutControl.DocumentFilename))
{ // 创建一个新的地图文档实例
IMapDocument mapDoc = new MapDocumentClass();
// 打开当前地图文档
mapDoc.Open(m_pageLayoutControl.DocumentFilename, string.Empty);
// 用 PageLayout 中的文档替换当前文档中的 PageLayout 部分
mapDoc.ReplaceContents((IMxdContents)m_pageLayoutControl.PageLayout);
// 保存地图文档
mapDoc.Save(mapDoc.UsesRelativePaths, false);
mapDoc.Close(); } }
private void SaveAs_Click(object sender, EventArgs e)
{ // 调用另存为命令
ICommand command = new ControlsSaveAsDocCommandClass();
command.OnCreate(m_controlsSynchronizer.ActiveControl);
command.OnClick(); }
添加完成后运行时的界面如下图所示:
在这里插入图片描述
2、MapControl 与PageLayoutControl 同步
为了能够很方面地进行MapView 和Layout View 两种视图的切换,以及二者之间的数据是同步显示,比较简单的方法莫过于二者共享一份地图了,这也是最常用的方法。首先要新建同步类ControlsSynchronizer,新建Maps 类、新建打开文档类OpenNewMapDocument,并在OnClick 函数中添加相应代码,进而实现两种视图的同步。
3、状态栏信息的添加与实现
应用程序的状态栏一般用来显示程序的当前状态,当前所使用的工具。GIS 应用程序一般也在状态栏显示当前光标的坐标、比例尺等信息。为了实现此功能,首先我们要添加状态栏项目、然后显示当前所用工具信息、显示当前比例尺、显示当前坐标,。运行界面截图如下图所示:
在这里插入图片描述
4、按照属性查询
按照属性查询时,要对待查询图选择相应的字段、图层,然后设置属性进行查询,查询是设计界面如下:
在这里插入图片描述
按照属性查询时代码如下:
private void 属性ToolStripMenuItem_Click(object sender, EventArgs e)
{ //初始化属性查询窗体
AttributeQueryForm attributeQueryForm = new AttributeQueryForm(this.axMapControl1);
attributeQueryForm.Show(); }
private DataTable LoadQueryResult(AxMapControl mapControl, IFeatureLayer featureLayer, IGeometry geometry)
{IFeatureClass pFeatureClass = featureLayer.FeatureClass;//根据图层属性字段初始化DataTable
IFields pFields = pFeatureClass.Fields;
DataTable pDataTable = new DataTable();
for (int i = 0; i < pFields.FieldCount; i++)
{ string strFldName;
strFldName = pFields.get_Field(i).AliasName;
pDataTable.Columns.Add(strFldName); }
ISpatialFilter pSpatialFilter = new SpatialFilterClass();
pSpatialFilter.Geometry = geometry;
//根据图层类型选择缓冲方式
switch (pFeatureClass.ShapeType)
{ case esriGeometryType.esriGeometryPoint:
pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains; break;
case esriGeometryType.esriGeometryPolyline:
pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses; break;
case esriGeometryType.esriGeometryPolygon:
pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; break; }
//定义空间过滤器的空间字段
pSpatialFilter.GeometryField = pFeatureClass.ShapeFieldName;
IQueryFilter pQueryFilter;
IFeatureCursor pFeatureCursor;
IFeature pFeature;
//利用要素过滤器查询要素
pQueryFilter = pSpatialFilter as IQueryFilter;
pFeatureCursor = featureLayer.Search(pQueryFilter, true);
pFeature = pFeatureCursor.NextFeature();
while (pFeature != null)
{ string strFldValue = null;
DataRow dr = pDataTable.NewRow();//遍历图层属性表字段值,并加入pDataTable
for (int j = 0; j < pFields.FieldCount; j++)
{ string strFldName1 = pFields.get_Field(j).Name;
if (strFldName1 == “Shape”)
{ strFldValue = Convert.ToString(pFeature.Shape.GeometryType); }
else strFldValue = Convert.ToString(pFeature.get_Value(j));
dr[j] = strFldValue; }
pDataTable.Rows.Add(dr);//高亮选择要素
mapControl.Map.SelectFeature((ILayer)featureLayer, pFeature);
mapControl.ActiveView.Refresh();
pFeature = pFeatureCursor.NextFeature(); }
return pDataTable; }
程序运行时截图如下:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
5、按照空间位置查询
按照空间位置进行查询时,首先要选择图层,然后选择查询方式,查询方式包括点、线、圆、矩形4种方式,按照位置查询代码如下:
private void 位置ToolStripMenuItem_Click(object sender, EventArgs e)
{ SpatialQueryForm spatialQueryForm = new SpatialQueryForm(this.axMapControl1);
if (spatialQueryForm.ShowDialog() == DialogResult.OK)
{ //标记为“空间查询”,获取查询方式和图层
this.mTool = “SpaceQuery”;
this.mQueryMode = spatialQueryForm.mQueryMode;
this.mLayerIndex = spatialQueryForm.mLayerIndex;
this.axMapControl1.MousePointer=ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerCrosshair; }
}
Private void axMapControl1 _OnMouseDown (objectsender, IMapControl Events2_OnMouseDownEvent e)
{ //清空上次选择的结果
this.axMapControl1.Map.ClearSelection();
switch (mTool)
{ case “SpaceQuery”: //获取当前视图
ESRI.ArcGIS.Carto.IActiveView pActiveView = this.axMapControl1.ActiveView;//获取鼠标点
ESRI.ArcGIS.Geometry.IPoint pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
ESRI.ArcGIS.Geometry.IGeometry pGeometry = null;
switch (this.mQueryMode)
{case 0: //矩形查询
pGeometry = this.axMapControl1.TrackRectangle(); break;
case 1: //线查询
pGeometry = this.axMapControl1.TrackLine(); break;
case 2: //点查询
ESRI.ArcGIS.Geometry.ITopologicalOperator pTopo;
ESRI.ArcGIS.Geometry.IGeometry pBuffer;
pGeometry = pPoint;
pTopo = pGeometry as ESRI.ArcGIS.Geometry.ITopologicalOperator;
//根据点位创建缓冲区,缓冲半径设为0.1,可自行修改
pBuffer = pTopo.Buffer(0.1);
pGeometry = pBuffer.Envelope; break;
case 3: //圆查询
pGeometry = this.axMapControl1.TrackCircle();
break; }
ESRI.ArcGIS.Carto.IFeatureLayer pFeatureLayer = this.axMapControl1.Map.get_Layer(this.mLayerIndex) as ESRI.ArcGIS.Carto.IFeatureLayer;
DataTable pDataTable = this.LoadQueryResult(axMapControl1, pFeatureLayer, pGeometry);
this.dataGridView1.DataSource = pDataTable.DefaultView;
this.dataGridView1.Refresh(); break; default: break; } }
程序运行时,选择好图层与查询方式后如下图所示,然后在图上用矩形框选一定区域,如下图所示,查询结果亦见下图。
在这里插入图片描述
在这里插入图片描述

  • 30
    点赞
  • 210
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
Visual Studio(VS)是一个非常流行的集成开发环境(IDE),它可以用于开发各种类型的应用程序,包括GIS应用程序。GIS(地理信息系统)是一种用于存储、管理、分析和展示地理信息的系统。GIS应用程序可以用于许多不同的领域,例如城市规划、环境管理、土地管理、农业、水资源管理等等。 在Visual Studio中进行GIS二次开发,需要使用某些GIS开发工具包或GIS开发框架。以下是一些常用的GIS开发工具包或GIS开发框架: 1. ArcGIS Runtime SDK for .NET:这是一款由Esri公司开发的GIS开发框架,它可以用于开发跨平台的GIS应用程序,包括桌面应用程序、Web应用程序和移动应用程序。 2. MapWinGIS:这是一款开源的GIS开发工具包,它可以用于开发桌面应用程序,支持多种GIS数据格式。 3. SharpMap:这是一款开源的GIS开发框架,它可以用于开发Web应用程序和桌面应用程序,支持多种GIS数据格式。 4. DotSpatial:这是一款开源的GIS开发框架,它可以用于开发桌面应用程序和Web应用程序,支持多种GIS数据格式。 在使用这些工具包或框架进行GIS二次开发之前,您需要了解一些GIS基础知识,例如GIS数据格式、地图投影、坐标系统等等。同时,您还需要了解一些编程语言,例如C#、VB.NET等等。如果您是GIS初学者,建议您先学习一些基础知识,然后再开始进行GIS二次开发

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值