AE邻近分析报告及渲染代码_第1页
AE邻近分析报告及渲染代码_第2页
AE邻近分析报告及渲染代码_第3页
AE邻近分析报告及渲染代码_第4页
AE邻近分析报告及渲染代码_第5页
已阅读5页,还剩29页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、实用实验六:基于最邻近模型的服务区分析文档题目要求:棒球队球迷范围分析芝加哥小熊队芝加哥白袜队I I* , 基本数据3 S Map2S0 th球队位置H chitrt centA 人口居住区的质心基于最邻近模型的基本分析思路基本思路用质心代表小区来计算到球队的距闊将小区纳入最近球队的服务区实验要求在上述数据的基础上实现一个最邻近服务区分析的 功能,用户操作方式自由定义,但结果形式定义如下書 运行结果保存在”人口居住区”所在的要素类中由以下三个字段存 储 ServLayer:字符串类型*存储球队位置图层的名称 NearServ:整数类型存储小区最近球队要素的冋D NearDist:浮点数类型,存

2、储小区到球队要素的距离利用NearServ字段的信息将“人口居住区”图层进行唯一值分类渲染计算两点间距离的方法ArcGIS Developer Help (ESRLArcGlS Carto) IMapXomputeDistance MethodComputes the distance between two points on the map and returns the result.Visual HNETjPublic Function ComputeDie tance ( By Vai pl Ab IPomt,ByVal p2 As IPoint Aa DoubleC*public

3、double ComputeOiatance ( IPointpl.IPointp;假设以芝加哥著名的小熊队和白袜队为例,使用了芝加哥大都市 统计区W个县的人口普査小区地理信息数据(包括普査小区多边 形及相关的面积.人口等属性)、球队所在的Cook县路网 Shapefile数据两队地址及赢球纪录数据其中普査小区地理信 息数据来源于美国人口局官方网站,Cook县路网数据来源于ESRI 网站,球队数据来源于美国职业棒球大联盟(IVILB)官方网站,分析过程大体分为3个步骤:球队定位、临近小区分析、结果显示。球队定位首先要根据ArcGIS系统提供的美国街道分区数据文件和Cook县路网图层创建地址匹配

4、器对象,然后使用该对象将球队数据 匹配到路网图层中,形成新的具备球队空间信息和属性信息的球队 图层;临近小区分析首先要利用空间分析中Feature To Point功 能创建普查小区的质心图层,然后使用Near分析功能创建距离 每个小区最近的球队数据表,最后使用“数据表连接”功能将该数 据表连接到普査小区图层,得到各个球队的服务区分布数据表;结 果显示指的是利用ArcGIS的分级显示功能,按照服务区分布数据表用不同颜色显示各个普査小区。以“临近小区分析”过程为例1) Forml主界面搭建:Forml.c* fiS计Fom2rC5 Form2.cs Ett ProgrMX5 EngineFumc

5、tfonxs Formlxsj menuStripl2 ) Form2用于邻近分析和唯一值渲染的界面搭建:Form2.csForm2. 避计xProgrami.es EngineFu ndionxs Form l.csForm-lxs 设计*要注意的几点:2.1首先将实验数据存放在系统工程文件夹bin Debug文件夹中,修改日期黄型2013/6/5 Z62013/6/5 0:152013/6/5 0rl52013/6/5 0:372013/6/5 0:372013/5/52013/6/5 0:272013/6/5 2:022013/6/5 1:002013/6/5 1:002013/6/5

6、&262013/6/5 0:37排列方式:如图:文件夹*Xh文档库bir名称Release文彳快 文彳换 文彳桂Visual C# Sourc., Visual C# Sourcn Visual C# Sourc., .NET Managed . Visual 5 Sourc. Visual C孝 Sousrc. ,NET Managed . Visual Sourc., Visual 匚# Projec,13 K03 KB9 K012 KB12 KB11 KB10 KB1 KB7 KB修改已期2013/6/5 2r01立件央2013/6/5 0:36文悻修改日期大小2013/5/29 23;

7、20DBF文件213 KB2O13/S/29 23:20Ultra Ed ft Docum.1 KB2013/5/29 23:20SBN文件18 KB2013/5/29.23:201 KB2013/5/29 23s2O5HP立禅53 KB2013/5/29 23:20UltraEdit DoCum.8 KB2013/5/29 23:20諒乂文件15 KB2013/6/5 2:28DBF文禅213 KB2011/5/1 19:46UltraEdit Do cum.1 KB2D13/6/5 2:27SEN立件IS KB2013/6/5 2:27SBX文件2 KB2013/6/5 2:2SSHPW2

8、.009 KB2013/6/5 2:28SHX文件15 KB2011/9/12 22:29DBF划牛2 KB2011/3/12 22:29UltraEdit Docum.1 KB排列右式:文件夹文档库D 巳 bug移股(V)Del裁名)却截顷吕J在Window?资灑音理器中打讦文件夹凶S 属性血Alt+Enter首I;訥国I匡1阖员 彳解辰方案六” (1个项目列 Properties崔習 EngineFunction,csForm LesT Form2心筍 Program.es2.3如果引用命名空间时出现了红波浪线,则需在解决方案资源管理器中添加引用,选 择.NET环境下的以ESRI.ArcG

9、IS开头的命名空间的引用,则代码中的红波浪则会消除,女口图:ao瀋加引用,号|项目|测S |最近鋳选为:.NET Framework M5组样名称版本运行时路径*ESRLArcGIS.ADFv2,0l50727C;Program Files (k36).,ESRLArcGlS.ADF,Local4650727C:Program Files (k36)V.ESRLArcGISn AnimationIOhOhO.0v2jOl50727匚:Program Files (kS6)V.,ESRIArcGISAnimstionLIIV2.0.50727C:P

10、rogram Files (kS6)V.ESRLArcGIS.ArcCatalcglOrOnO.Ov2.0h50727C:Prograin Files (xS5)V.ESRLArcGISrArtCatalog Ulv2,0.50727C:Program Files (xS6)+.ESRLArcGISrArtGlabeV2.0.50727C:Program Filts (xS5),.ESRIrArcGIS.ArcMapvZ0l50727C:Program Files (xS5),.ES RI .ArcGIS .ArcM 3 pUIv

11、2.0.50727CiProgram Files (xS5),.ESRI.ArcGIS.ArcScanv2.0.50727C:Program Files (x86),.ESRJJKrcGIS. ArcScene10.0,0.0v2.O.5O727C:Proaram Files fxS&A. | 4庐走取消3)如果用于 Visual2010+ArCGIS10.0 所组成的 ArcGIS Engine 中:Program.es中需添加一句话用于格式转换:using System;using System.Collections.Generic;using System.Linq;u

12、sing System.Windows.Forms;namespace 六static class Program STAThreadstatic void Main()Application .EnableVisualStyles();ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS. ProductCode .EngineOrDesktop);Application .SetCompatibleTextRenderingDefault( false );Application .Run( new Form1();4) Form1 代码:using Sy

13、stem;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using ESRI.ArcGIS.Controls;using ESRI.ArcGIS.Carto;using ESRI.ArcGIS.Geodatabase;using SystemO;using ESRI.ArcGIS.Display;using ESRI.

14、ArcGIS.esriSystem;using ESRI.ArcGIS.DataSourcesFile;using ESRI.ArcGIS.Geometry;namespace 六public partial class Form1 : Formpublic Form1()lnitializeComponent();private void Form1_Load( object sender, EventArgs e)private void 文件 tToolStripMenultem_Click( object sender, EventArgs e)IWorkspaceFactory pW

15、orkspaceFactory = new ShapefileWorkspaceFactoryClass (); string ShpPath = Application .StartupPath +服务区分析数据;IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(ShpPath, 0);IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace ;IFeatureClass pFeat1 = pFeatureWorkspace.OpenFeatureCl

16、ass( cubsoxaddr_prj.shp );IFeatureLayer pFLayerPoint = new FeatureLayerClass ();pFLayerPoint.FeatureClass = pFeat1;pFLayerPoint.Name = pFeat1.AliasName;ILayer pLayerPoint = pFLayerPoint as ILayer ;IFeatureClass pFeat2 = pFeatureWorkspace.OpenFeatureClass( chitrt_cent.shp );IFeatureLayer pFLayerPeopl

17、ePoint = new FeatureLayerClass ();pFLayerPeoplePoint.FeatureClass = pFeat2;pFLayerPeoplePoint.Name = pFeat2.AliasName;ILayer pLayerPeoplePoint = pFLayerPeoplePoint as ILayer ;IFeatureClass pFCLine = pFeatureWorkspace.OpenFeatureClass( chitrt_polygon.shp );IFeatureLayer pFLayerLine = new FeatureLayer

18、Class ();pFLayerLine.FeatureClass = pFCLine;pFLayerLine.Name = pFCLine.AliasName;ILayer pLayerLine = pFLayerLine as ILayer ;IMap pMap = axMapControl1.Map;pMap.AddLayer(pLayerLine);pMap.AddLayer(pLayerPeoplePoint);pMap.AddLayer(pLayerPoint);axMapControl1.ActiveView.Refresh();邻近分析 ToolStripMenuItem.En

19、abled =true ;打开文件 ToolStripMenuItem.Enabled =false ;private void 邻近分析 _Click( object sender, EventArgs e)lObjectCopy objectCopy = new ObjectCopyClass ();object toCopyMap = axMapControll.Map;object copiedMap = objectCopy.Copy(toCopyMap);IMap pMap = copiedMap as IMap;Form2 AccFrom = new Form2(pMap);Ac

20、cFrom.ShowDialog();5) Form2 代码:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using Syste m. Linq;using System.Text;using System.Windows.Forms;using ESRI.ArcGIS.Carto;using ESRI.ArcGIS.Geodatabase;using ESRI.ArcGIS.Display;using ESRI.

21、ArcGIS.Geometry;using System.Threading;namespace 六public partial class Form2 : FormIMap MainMap = null;IFeatureLayer ServiceLayer = null;IFeatureLayer ResidualLayer = null;IFeatureLayer ResidulLayerPoint = null;string DmdFieldName = null;public Form2(IMap mainMap)this.MainMap = mainMap;ILayer pLayer

22、 = EngineFunction.GetLayerByName(MainMap, chitrt_polygon);IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;添加一个EngineFunction.AddField(pFeatureLayer,结果字段, esriFieldType.esriFieldTypelnteger); /字段结果字段,用来保存计算结果lnitializeComponent();for (int i = 0; i MainMap.LayerCount; i+)comboBoxI .I tems.Add(Ma

23、inMap.get_Layer(i).Name);comboBox2 .I tems.Add(MainMap.get_Layer(i).Name);comboBox3.ltems.Add(MainMap.get_Layer(i).Name);comboBox1.Selectedlndex = 0;comboBox2.Selectedlndex = 1;comboBox3.Selectedlndex = 2;comboBox4.Selectedlndex = 12;private void Form2_Load(object sender, EventArgs e)axMapControl1.M

24、ap = MainMap;button1.Enabled = false;private void comboBox3_SelectedlndexChanged(object sender, EventArgs e)comboBox4.ltems.Clear();ILayer pLayer = EngineFunction.GetLayerByName(MainMap, comboBox3.Text);IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;IFields pFields = pFeatureLayer.FeatureClas

25、s.Fields;for (int i = 0; i pFields.FieldCount; i+)comboBox4 .I tems.Add(pFields.get_Field(i).Name);comboBox4.Selectedlndex = 0;public static Thread CountThread = null;private void btn_Count_Click(object sender, EventArgs e)label5.Visible = true;ServiceLayer = EngineFunction.GetLayerByName(MainMap, c

26、omboBox1.Text) as IFeatureLayer;ResidualLayer = EngineFunction.GetLayerByName(MainMap, comboBox3.Text) as IFeatureLayer;ResidulLayerPoint = EngineFunction.GetLayerByName(MainMap, comboBox2.Text) as IFeatureLayer;DmdFieldName = comboBox4.Text;btn_Count.Enabled = false;comboBox1.Enabled = false;comboB

27、ox2.Enabled = false;comboBox3.Enabled = false;comboBox4.Enabled = false;CountThread = new Thread(new ThreadStart(StartCount); /防止计算时,界面处于假死未响应状态,申请一个线程单独执行运算。CountThread.Start();public void StartCo unt()JustC ontain s(ServiceLayer, ResidualLayer, DmdFieldName, ResidulLayerPo in t);IWorkspaceEdit pWo

28、rkspaceEdit;/ ServiceLayer就是服务区图层,里面有两个点,分别代表两个队该图层文件名cubsoxaddr_prj/ResiduaLayer是居民区图层,因为最后要对它进行渲染,所有要把计算的结果保留到这个图层里,所以在这个图层里新建了一个字段,计算结果,也就是DmdFieldName变量 该图层的文件名chitrt_polygon/ResidulLayerPoi nt在计算服务区与点之间的距离时,因为面和点的距离无法计算,所以就用面图层中,人口的矢量质心代替,每个面都对应一个点,这些点保存在ResidulLayerPoi nt图层中,该图层文件名 chitrt_ce n

29、tprivate void JustC ontain s(IFeatureLayer ServiceLayer, IFeatureLayer ResidualLayer, stri ng DmdFieldName, IFeatureLayer ResidulLayerP oint)IFeatureClass pResidulFeatureClass = ResidulLayerP oin t.FeatureClass;int CountPoint = pResidulFeatureClass.FeatureCo un t( null);SetMaxNum(Cou ntPoi nt);IQuer

30、yFilter pQueryFilter = new QueryFilterClass();IFeatureCursor pResidulFeatCursor = pResidulFeatureClass.Search (n ull, false);/有要素,每个要素的FID和面图层的FID对应,由此关系来找到面图层中对应的要素IFeature pResidulFeature = pResidulFeatCursor.NextFeature();读取第一个要素int ResidualFieldIndex = ResidualLayer.FeatureClass.Fields.FindField

31、(DmdFieldName); /层中找到“结果字段对应的索引Index ”获取居民点图层中的所在居民要素图IQueryFilter pQueryFilterServer = new QueryFilterClass();pQueryFilterServer.WhereClause = FID = 0;IFeature Cubs = ServiceLayer.FeatureClass.Search(pQueryFilterServer, false).NextFeature(); /获取小熊队的要素pQueryFilterServer.WhereClause = FID = 1;IFeatur

32、e WhiteSox = ServiceLayer.FeatureClass.Search(pQueryFilterServer, false).NextFeature();获取白袜队的要素IPoint CubsPoint = Cubs.Shape as IPoint; /把小熊队要素转化为点IPoint WhiteSoxPoint = WhiteSox.Shape as IPoint;/把白袜队要素转化为点IDataset pDataSet = ResidualLayer.FeatureClass as IDataset; /建立居民区图层的数据表IWorkspace pWorkspace

33、= pDataSet.Workspace;/pWorkspaceEdit = pWorkspace as IWorkspaceEdit; /pWorkspaceEdit.StartEditing(false);/pWorkspaceEdit.StartEditOperation(); /int iStep = 1;获取数据表的工作空间建立工作空间编辑器开始编辑开启应用程序编辑操作循环遍历 居民区点要素图层中的每一个要while (pResidulFeature != null)/int FID = ResidulLayerPoi nt.FeatureClass.Fields.Fi ndFiel

34、d(FID); /构中的索引值int FIDResult = Convert.Tolnt32(pResidulFeature.get_Value(FID);获取要素的FID字段在表结通过索引值获取对应要素的FIDpQueryFilterEdit.WhereClause = FID= + FIDResult; /通过居民区点要素图层中的FID找到居民区要素IQueryFilter pQueryFilterEdit = new QueryFilterClass();中相对应的要素获取IFeatureCursor pEditCursor = ResidualLayer.FeatureClass.Se

35、arch(pQueryFilterEdit, false);/居民区要素集合IFeature EditFeature = pEditCursor.NextFeature(); /因为只可能找到一个值,所以直接读取第一个要素就可以了IPoint pPoint = pResidulFeature.Shape as IPoint; /double DX1 = MainMap.ComputeDistance(pPoint, CubsPoint); /double DX2 = MainMap.ComputeDistance(pPoint, WhiteSoxPoint);/if (DX1 DX2)/居民区

36、点图层要素转化为点符号计算该点符号与小熊队的距离计算该点符号与白袜队的距离如果与小熊队比较接近EditFeature.set_Value(ResidualFieldlndex, 0); /把结果字段标记为0else/如果与白袜队比较接近EditFeature.set_Value(ResidualFieldlndex, 1);/把结果字段标记为EditFeature.Store(); /存储编辑SetStepNum(iStep); /此处与实验无关,只是加载进度条显示而已iStep+;pResidulFeature = pResidulFeatCursor.NextFeature(); /pWo

37、rkspaceEdit.StopEditOperati on();pWorkspaceEdit.StopEditing(true); /编辑完成继续读取下一个居民区点要素图层Application.DoEvents();MessageBox.Show(“计算完成!);SetVisable();private void button1_Click(object sender, EventArgs e)/这里就是单一值渲染IUniqueValueRenderer pRender = new UniqueValueRendererClass();pRender.FieldCount = 1;pRen

38、der.set_Field(0,结果字段);pRender.set_FieldType(0, false);IRgbColor pRGB = new RgbColorClass(); pRGB.Red = 0;pRGB.Green = 255;pRGB.Blue = 127;IFillSymbol pSymboll = new SimpleFillSymbolClass();pSymboll.Outline.Width = 0.4;pSymboll.Color = pRGB;pRender.AddValue(0,小熊队, pSymbol1 as ISymbol);IRgbColor pRGB2

39、 = new RgbColorClass();pRGB2.Red = 255;pRGB2.Green = 97;pRGB2.Blue = 0;IFillSymbol pSymbol2 = new SimpleFillSymbolClass();pSymbol2.Outline.Width = 0.4;pSymbol2.Color = pRGB2;pRender.AddValue(1,白袜队, pSymbol2 as ISymbol);ILayer ppp = GetLayerByName(MainMap, chitrt_polygon);IGeoFeatureLayer pGeoFLayer

40、= ppp as IGeoFeatureLayer;pGeoFLayer.Renderer = pRender as IFeatureRenderer;IActiveView pView = axMapControll.ActiveView;pView.ContentsChanged();pView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);public static ILayer GetLayerByName(IMap pMap, String layerName)ILayer layer = null;f

41、or (int i = 0; i pMap.LayerCount; i+)if (pMap.get_Layer(i).Name = layerName)layer = pMap.get_Layer(i);break;return layer;public delegate void MyInvoke(int Num);public delegate void CountrolInvoke();private void SetMaxNum(int Num)if (progressBarl .I nvokeRequired)Mylnvoke _mylnvoke = new Mylnvoke(Set

42、MaxNum); this .I nvoke(_myInvoke, new object Num );gressBarl.Maximum = Num;private void SetStepNum(int Num)if (progressBarl .I nvokeRequired)Mylnvoke _mylnvoke = new Mylnvoke(SetStepNum); this .l nvoke(_mylnvoke, new object Num );gressBarl.Value = Num;private void SetVisable(

43、)if (progressBarl .l nvokeRequired)Countrollnvoke _mylnvoke = new Countrollnvoke(SetVisable); this .l nvoke(_mylnvoke, new object );elsethis.buttonl.Enabled = true;if (label5 .l nvokeRequired)Countrollnvoke _mylnvoke = new Countrollnvoke(SetVisable); this .l nvoke(_mylnvoke, new object );elsethis.la

44、bel5.Visible = false;private void accessibilityForm_FormClosing(object sender, FormClosingEventArgs e) if (CountThread != null)if (CountThread.lsAlive)pWorkspaceEdit.StopEditOperation();pWorkspaceEdit.StopEditing(true); /编辑完成CountThread.Abort();6)在解决方案资源管理器中添加一个新类EngineFunction.cs,其中主要存储一些方法,代码如下:us

45、ing System;using System.Collections.Generic;using Syste m. Linq;using System.Text;using ESRI.ArcGIS.Controls;using ESRI.ArcGIS.Carto;using ESRI.ArcGIS.Geodatabase;using Syste m.IO;using ESRI.ArcGIS.Display;using ESRI.ArcGIS.esriSystem;using ESRI.ArcGIS.DataSourcesFile;using ESRI.ArcGIS.Geometry;name

46、space 六class EngineFunction/ /获取图层几何类型的属性字段值/ / vparam name=n_Layer/ public static string GetShpType(ILayer n_Layer)IFeatureLayer pFeatureLayer = n_Layer as IFeatureLayer;switch (pFeatureLayer.FeatureClass.ShapeType)case esriGeometryType.esriGeometryPoint:return Point;break;case esriGeometryType.esr

47、iGeometryPolyline:return Polyline;break;case esriGeometryType.esriGeometryPolygon:return Polygon;break;default:return ;break;/ /向属性表中添加字段/如果存在,则先删除后添加/ / / / public static void AddField(ILayer pLayer, string FieldName, esriFieldType Type)ITable LayerTable;LayerTable = pLayer as ITable;IField pField

48、= new FieldClass();IFieldEdit pFieldEdit;pFieldEdit = pField as IFieldEdit;pFieldEdit.Name_2 = FieldName;pFieldEdit.Type_2 = Type;IField tmpField = null;for (int i = 0; i LayerTable.Fields.FieldCount; i+)tmpField = LayerTable.Fields.get_Field(i);if (FieldName = tmpField.Name)LayerTable.DeleteField(tmpField);break;LayerTable.AddField(pField);public static void AddField(IFeatureLayer pFeatureLayer, string FieldName, esriFieldType Type) ISchemaLock pLock = pFeatureLayer.FeatureClass as ISchemaLock;ITable LayerTable = pFeatureL

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论