东华理工GIS二次开发实验报告

更新时间:2023-06-08 17:32:01 阅读量: 实用文档 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

GIS

二次开发实验报告学号: 姓 名: 班 级: 专 业: 指导老师:

二零一五年1月4日

目录

1

实验一:软件安装与AOI书签开发 .................................................................... 1 1.1 1.2 1.3 2

实验目的.......................................................................................................... 1 实验内容.......................................................................................................... 1 实验结果.......................................................................................................... 1

实验二:地图数据组织与访问 ............................................................................ 8 2.1 2.2 2.3

实验目的.......................................................................................................... 8 实验内容.......................................................................................................... 8 实验结果.......................................................................................................... 8

3 实验三:地图渲染与制图输出 ........................................................................ 133 3.1 3.2 3.3

实验目的...................................................................................................... 133 实验内容...................................................................................................... 133 实验结果...................................................................................................... 133

4 实验四:空间数据处理 .................................................................................... 188 4.1 4.2 4.3

实验目的...................................................................................................... 188 实验内容...................................................................................................... 188 实验结果...................................................................................................... 188

5 实验五:GIS分析 .............................................................................................. 189 5.1 5.2 5.3

实验目的...................................................................................................... 189 实验内容...................................................................................................... 189 实验结果...................................................................................................... 189

6 实验六:栅格数据处理 ...................................................................................... 24 6.1 6.2 6.3

实验目的........................................................................................................ 24 实验内容........................................................................................................ 24 实验结果........................................................................................................ 25

7 实验总结 .............................................................................................................. 28

1 实验一:软件安装与AOI书签开发

1.1 实验目的

掌握ArcGIS Engine开发环境的相关软件安装 掌握AOI书签程序开发

1.2 实验内容

安装Visual Studio 2010

安装Microsoft .NET Framework 3.5 安装ArcGIS Engine 10.1

安装ArcObjects Developer kit For Microsoft .NET Framework 10.1 安装ArcGIS License Manager,并授权 实现AOI书签的创建 实现AOI书签的调用

1.3 实验步骤与结果

安装VS2010

安装AE 10.0

打开VS 2010 选择ArcGIs—Extending ArcObjects—MapControl Application

打开界面如图所示

给窗体添加一个书签窗体

输入如下代码

C# Code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

using System;

using System.Collections.Generic; using ponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;

using System.Windows.Forms;

namespace MapControlApplication1 {

public partial class admitBookmarkName : Form {

public admitBookmarkName(MainForm frm) { InitializeComponent(); if (frm != null) {

m_frmMain = frm; } }

public MainForm m_frmMain;

private void 确定_Click(object sender, EventArgs e) {

if (m_frmMain != null && tbbookmarkname.Text != "") m_frmMain.creatbookmark(tbbookmarkname.Text); this.Close(); } } }

输入如下代码,用来添加书签

C# Code 1 2

3 4 5 6 7 8 9 10 11 12 13

public void creatbookmark(string sbookmarkname) {

IAOIBookmark aoibookmark = new AOIBookmarkClass(); if (aoibookmark != null) {

aoibookmark.Location = axMapControl1.ActiveView.Extent; = sbookmarkname; }

IMapBookmarks bookmarks = axMapControl1.Map as IMapBookmarks; if (bookmarks != null)

bookmarks.AddBookmark(aoibookmark);

跳转书签ToolStripMenuItem.DropDownItems.Add(); }

C# Code 1 2

3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

private void 跳转书签ToolStripMenuItem_DropDownItemClicked (object sender, ToolStripItemClickedEventArgs e) {

IMapBookmarks bookmarks = axMapControl1.Map as IMapBookmarks; IEnumSpatialBookmark enumbookmark = bookmarks.Bookmarks; enumbookmark.Reset();

ISpatialBookmark spabookmark = enumbookmark.Next(); while (spabookmark != null)

{ if (e.ClickedItem.ToString() == ) {

spabookmark.ZoomTo((IMap)axMapControl1.ActiveView); axMapControl1.ActiveView.Refresh(); break; }

spabookmark = enumbookmark.Next(); } }

运行程序,如图方式添加书签

查看已添加书签并点击跳转

2 实验二:地图数据组织与访问

2.1 实验目的

了解ArcGIS Engine中地图数据的组织结构 掌握ArcGIS Engine地图数据访问方法

2.2 实验内容

编写“数据操作”类

利用DataGridView控件展示Continents图层的序号和名称字段

2.3 实验步骤与结果

添加dataoperator类,代码如下

C# Code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

using System;

using System.Collections.Generic; using System.Linq; using System.Text; using System.Data;

using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.ADF; using ESRI.ArcGIS.SystemUI;

using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.Display;

using ESRI.ArcGIS.DataSourcesFile; using ESRI.ArcGIS.Geodatabase; namespace MapControlApplication1 {

class dataoperator {

public IMap mmap;

public dataoperator(IMap map)

21 {

22 mmap = map; 23 }

24 public ILayer getlayerbyname(string slayername) 25 {

26 if (slayername == "" || mmap == null) return null; 27 for (int i = 0; i < yerCount; i++) 28 if (mmap.get_Layer(i).Name == slayername) 29

31 } 32

33 public IFeatureClass createshapefile

34 (string sparentdirection, string sworkspc, string sfilename) 35 {

36 if (System.IO.Directory.Exists(sparentdirection + sworkspc)) 37 System.IO.Directory.Delete(sparentdirection + sworkspc, true); 38 IWorkspaceFactory workspacef = 39

new ShapefileWorkspaceFactoryClass();

40 IWorkspaceName workname; 41 workname = 42

workspacef.Create(sparentdirection, sworkspc, null, 0);

43 IName name = workname as IName;

44 IWorkspace workspace = (IWorkspace)name.Open(); 45 IFeatureWorkspace ftworkspace = 46

workspace as IFeatureWorkspace;

47 IFields fields = new FieldsClass();

48 IFieldsEdit fieldsedit = fields as IFieldsEdit; 49 IFieldEdit fedit = new FieldClass(); 50 _2 = "OID"; 51 fedit.AliasName_2 = "序号";

52 fedit.Type_2 = esriFieldType.esriFieldTypeOID; 53 fieldsedit.AddField((IField)fedit); 54 fedit = new FieldClass(); 55 _2 = "Name"; 56 fedit.AliasName_2 = "名称";

57 fedit.Type_2 = esriFieldType.esriFieldTypeString; 58 fieldsedit.AddField((IField)fedit);

59 IGeometryDefEdit geodefedit = new GeometryDefClass(); 60 ISpatialReference sparef = mmap.SpatialReference; 61 geodefedit.SpatialReference_2 = sparef; 62 geodefedit.GeometryType_2 = 63

esriGeometryType.esriGeometryPoint;

64 fedit = new FieldClass();

return mmap.get_Layer(i);

30 return null;

65 string shapefilename = "Shape"; 66 _2 = shapefilename; 67 fedit.AliasName_2 = "形状";

68 fedit.Type_2 = esriFieldType.esriFieldTypeGeometry; 69 fedit.GeometryDef_2 = geodefedit; 70 fieldsedit.AddField((IField)fedit); 71

72 IFeatureClass ftclass;

73 ftclass = ftworkspace.CreateFeatureClass 74 (sfilename, fields, null, null, 75

esriFeatureType.esriFTSimple, "Shape", "");

76 if (ftclass == null) 77 return null; 78 return ftclass; 79 } 80

81 public bool addfeaturetomap 82

83 {

84 if (ftclass == null || slayername == null) 85 return false;

86 IFeatureLayer ftlayer = new FeatureLayerClass(); 87 ftlayer.FeatureClass = ftclass; 88 = slayername; 89 mmap.AddLayer(ftlayer as ILayer); 90 IActiveView act = mmap as IActiveView; 91 act.Refresh(); 92 return true; 93 } 94

95 public DataTable getcontNames() 96 {

97 ILayer layer = getlayerbyname("Continents");

98 IFeatureLayer featurelayer = layer as IFeatureLayer; 99 if (featurelayer == null) 100 return null; 101 IFeature feature;

102 IFeatureCursor featureCursor = featurelayer.Search(null, false); 103 feature = featureCursor.NextFeature(); 104 if(feature == null) 105 return null;

106 DataTable datatable = new DataTable(); 107 DataColumn datacolum = new DataColumn(); 108 datacolum.ColumnName = "序号";

(IFeatureClass ftclass, string slayername)

109 datacolum.DataType = System.Type.GetType("System.String"); 110

datatable.Columns.Add(datacolum); 111 datacolum = new DataColumn(); 112 datacolum.ColumnName = "名称";

113 datacolum.DataType = System.Type.GetType("System.String"); 114 datatable.Columns.Add(datacolum); 115 DataRow datarow; 116 while(feature != null) 117 {

118 datarow = datatable.NewRow(); 119 datarow[0] = feature.get_Value(0); 120 datarow[1] = feature.get_Value(2); 121 datatable.Rows.Add(datarow);

122 feature = featureCursor.NextFeature(); 123 }

124 return datatable; 125 } 126 } 127 }

新建databord窗体

主窗体新建菜单“空间数据”,并添加如下代码

C# Code

1 private void 访问图层数据ToolStripMenuItem_Click(object sender, EventArgs e) 2

{

3 dataoperator Dataoperate = new dataoperator(axMapControl1.Map); 4 databoard databoard = 5

}

new databoard("各大洲州名", Dataoperate.getcontNames());

6 databoard.Show();

点击“空间数据”得到空间数据表

3 实验三:地图渲染与制图输出

3.1 实验目的

了解地图符号的分类与可视化过程 掌握地图符号的渲染方法

3.2 实验内容

编写“地图编制”类,添加成员函数 实现获取地图渲染器信息功能 实现地图的简单符号渲染

3.3 实验步骤

C# Code

1 private void 简单渲染图层ToolStripMenuItem1_Click(object sender, EventArgs e) 2 {

3 dataoperator dataOperator = new dataoperator(axMapControl1.Map); 4 ILayer layer = dataOperator.getlayerbyname("World Cities"); 5 IRgbColor rgbColor = new RgbColorClass(); 6 rgbColor.Blue = 0; 7 rgbColor.Red = 255; 8 rgbColor.Green = 0;

9 IColor color = rgbColor as IColor;

10 ISymbol symbol = MapComposer.getsymbolfromlayer(layer); 11 bool res = MapComposer.RenderSimply(layer, color);

12 if(res) 13 {

14 axMapControl1.ActiveView.ContentsChanged(); 15 axMapControl1.ActiveView.Refresh();

16 简单渲染图层ToolStripMenuItem.Enabled = false; 17 } 18 else 19 {

20 MessageBox.Show("简单渲染图层失败"); 21 } 22 }

主窗体新建渲染图层菜单,并新建子菜单

C# Code

1 private void 获取渲染器信息ToolStripMenuItem_Click(object sender, EventArgs e) 2 {

3 dataoperator dataOperator = new dataoperator(axMapControl1.Map); 4 ILayer layer = dataOperator.getlayerbyname("World Cities"); 5 MessageBox.Show(MapComposer.getrendertypebylayer(layer)); 6 }

新建MapComposer类并输入以下代码 C# Code

1 using System;

2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text;

5 using ESRI.ArcGIS.esriSystem; 6 using ESRI.ArcGIS.Carto;

7 using ESRI.ArcGIS.Controls; 8 using ESRI.ArcGIS.ADF; 9 using ESRI.ArcGIS.SystemUI; 10 using ESRI.ArcGIS.Geometry; 11 using ESRI.ArcGIS.Display; 12 using ESRI.ArcGIS.Geodatabase;

13 namespace MapControlApplication1 14 {

15 class MapComposer 16 {

17 public static string getrendertypebylayer(ILayer layer) 18 {

19 if(layer == null) 20 return "获取失败";

21 IFeatureLayer ftly = (IFeatureLayer)layer; 22 IGeoFeatureLayer gftly = (IGeoFeatureLayer)layer; 23 IFeatureRenderer ftren = gftly.Renderer; 24 if(ftren is ISimpleRenderer) 25 return "ISimpleRenderer";

26 else if(ftren is IUniqueValueRenderer) 27 return "IUniqueValueRenderer"; 28 else if(ftren is IDotDensityRenderer) 29 return "IDotDensityRenderer"; 30 else if(ftren is IChartRenderer) 31 return "IChartRenderer";

32 else if(ftren is IProportionalSymbolRenderer) 33 return "IProportionalSymbolRenderer"; 34 return "未知或者获取渲染器失败"; 35 }

36 public static ISymbol getsymbolfromlayer(ILayer layer) 37 {

38 if(layer == null) 39 return null;

40 IFeatureLayer ftly = (IFeatureLayer)layer; 41 IFeatureCursor ftcs = ftly.Search(null, false); 42 IFeature ft = ftcs.NextFeature(); 43 if(ft == null) 44 return null;

45 IGeoFeatureLayer gftly = ftly as IGeoFeatureLayer; 46 IFeatureRenderer ftren = gftly.Renderer; 47 if(ftren == null) 48 return null;

49 ISymbol syb = ftren.get_SymbolByFeature(ft); 50 return syb; 51 }

52 public static bool RenderSimply(ILayer layer, IColor color) 53 {

54 if(layer == null || color == null) 55 return false;

56 ISymbol symbol = getsymbolfromlayer(layer);

57 if(symbol == null) 58 return false;

59 IFeatureLayer featureLayer = layer as IFeatureLayer; 60 IFeatureClass featureClass = featureLayer.FeatureClass; 61 if(featureClass == null) 62 return false;

63 esriGeometryType geoType = featureClass.ShapeType; 64 switch(geoType) 65 {

66 case esriGeometryType.esriGeometryPoint: 67 {

68 IMarkerSymbol markerSymbol = symbol as IMarkerSymbol; 69 markerSymbol.Color = color; 70 break; 71 }

72 case esriGeometryType.esriGeometryMultipoint: 73 {

74 IMarkerSymbol markerSymbol = symbol as IMarkerSymbol; 75 break; 76 }

77 case esriGeometryType.esriGeometryPolyline: 78 {

79 ISimpleLineSymbol simpleLineSymbol = 80

symbol as ISimpleLineSymbol;

81 simpleLineSymbol.Color = color; 82 break; 83 }

84 case esriGeometryType.esriGeometryPolygon: 85 {

86 IFillSymbol fillSymbol = symbol as IFillSymbol; 87 fillSymbol.Color = color; 88 break; 89 } 90 default:

91 return false; 92 }

93 ISimpleRenderer simpleRenderer = new SimpleRendererClass(); 94 simpleRenderer.Symbol = symbol; 95 IFeatureRenderer featureRenderer = 96

simpleRenderer as IFeatureRenderer;

97 if(featureRenderer == null) 98 return false;

99 IGeoFeatureLayer geoFeatureLayer = featureLayer as IGeoFeatureLayer;

geoFeatureLayer.Renderer = featureRenderer; return true; }

} }

运行“获取渲染器信息”

运行“简单渲染器渲染”

4 实验四:空间数据处理

4.1 实验目的

了解创建空间数据的过程 掌握创建空间数据的方法

4.2 实验内容

实现创建Shapefile文件的程序 实现新增点要素程序

4.3 实验步骤与结果

主窗体添加“添加shapefile”菜单

C# Code

1 private void 添加shapefileToolStripMenuItem_Click(object sender, EventArgs e) 2 {

3 dataoperator dtoprt = new dataoperator(axMapControl1.Map); 4 IFeatureClass ftclss = 5 6 ;

7 if(ftclss == null) 8 {

9 MessageBox.Show("创建失败"); 10 return; 11 }

12 bool bres = dtoprt.addfeaturetomap(ftclss, "observation"); 13 if(bres) 14 {

15 添加shapefileToolStripMenuItem.Enabled = false; 16 return; 17 } 18 else

19 MessageBox.Show("出错了!"); 20 return; 21 }

dtoprt.createshapefile("C:\\", "shapefileworkspace", "shapefileSample")

5 实验五:GIS分析

5.1 实验目的

了解GIS空间分析的内容 掌握空间关系查询方法 掌握空间拓扑分析方法 掌握空间数据统计方法

5.2 实验内容

实现空间关系查询程序 实现缓冲区分析程序 实现要素统计程序

本文来源:https://www.bwwdw.com/article/zff1.html

Top