GIS软件工程实习报告材料(最短路径分析报告).doc

上传人:scccc 文档编号:13596048 上传时间:2022-01-19 格式:DOC 页数:23 大小:842.50KB
返回 下载 相关 举报
GIS软件工程实习报告材料(最短路径分析报告).doc_第1页
第1页 / 共23页
GIS软件工程实习报告材料(最短路径分析报告).doc_第2页
第2页 / 共23页
GIS软件工程实习报告材料(最短路径分析报告).doc_第3页
第3页 / 共23页
亲,该文档总共23页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《GIS软件工程实习报告材料(最短路径分析报告).doc》由会员分享,可在线阅读,更多相关《GIS软件工程实习报告材料(最短路径分析报告).doc(23页珍藏版)》请在三一文库上搜索。

1、AE开发之基于几何网络的最短路径分析1、实习目的本次实习目的在于熟练掌握 ArcGIS Engine开发工具并能够通过C#语言在VS 2010开发环境中完成查询几何网络的最短路径分析的功 能。2、实习时间2015年5月23日星期六3、实习内容3.1实验环境操作系统:Win dows 2007二次开发平台:VS 2010开发环境、ArcGIS Desktop10.0 AE开发组件3.2实验任务完成基于几何网络分析的最短路径查询功能,即实现通过在几何 网络地图中指定起始点,能够查询经过起始点的最短路线,并能够通 过缩放功能在地图窗口居中显示。3.3实验步骤新建项目选择 文件 新建项目,如图选择项目

2、类型中Visual C#,再选择 WindowsApplication ,记为 FindShortPath ”点击确定。| .NfT fra-n&jvQrk 4 痛邛右E:斗乂也VnUfl日却忙*隔心耐dan1AMA, Gli3d:目V r JSVituai C*Vitual aReporting SbifF 卢口 iirrl Sii*e right WFWindcw& 弗鴛Visua Vi - Jfl 5WorkFer注L);3汕日口l多肓*宮护阳h添加控件控件绑定因为添加的控件只是单独存在,但是程序需要各控件间协同工作,因此要进行控件绑定1-esriBorderAppear 辺 ug:0-

3、tsriFlat0-w詁ifoinZD涎沁 tLkbtL0 一 e sr i TOCC o ntro lAut om a.i Layer0 - t sr i TOCC fi ti+r t Unit 6ft si 仃BuddyaMapControll奮训勰皿m丿 En&blftlEnable LayerDr ag an d Or op_ Prevjew in Dw】gn MotArrow Kty In+src*pt| 确定瞬应用.帮肋创建几何网络1.在ArcCataLog中新建个人地理数据库一“甘地的个人地理数据库”,然后 新建要素数据集“ road”,接着,鼠标右键选择要素数据集“ road”

4、,选择“导入 要素类”,导入需要创建几何网络的要素类 “主要公路”,输出要素类的名字改为“road”,如下图所示:.f r二 41”1tf?al* ydb丟捋5阿|.rTUtUXffSiR -| 土暑r O*. St=IF?J暫AH君,|.副曲C VJir aiB3 x-Lr a-i ekf *iIjc-Bk: spAc cGJ.aF-IS xbpjj-TE 炬更悝、L-Mbr-LJ-8-jj i 中|Jkr rf?t三失总Lh-n :卫云-:3TlfllmmsJ-K- -I J n.usgrf pu ip O-SBH th?Ui =工6, E.”pLDHM_e.,hp二三氏碟如* .:广于看

5、港 II a a2.鼠标右键选择要素数据集road ”,选择新建“几何网络”,则出现“新建几何网络”对话框,作如下图所示的一系列设置,最终得到几何网络“road Net至此,得到几何网络“ road_Net”,如下图所示:代码实现最短路径分析设置 ToolStripl甘is室习添加代码privatelActiveViewmpActiveView;private IMapm_ipMap; 地图控件中地图private IGraphicsCo nta in erpGC;/图形对象privatebool clicked = false;in tclickedco unt = 0;private do

6、uble m_dblPathCost = 0;private IGeometricNetworkm_ipGeometricNetwork;private IPoi ntCollectio nmpPoi nts;输入点集合privateIPo in tToEIDm_ipPo in tToEID;private lEnum NetEIDm_ipE num NetEID_J un ctio ns;private lEnum NetEIDm_ipE num NetEID_Edges;private IPolyli nem_ipPolyli ne;private IMap Co ntrol3 map c

7、trlMai nMap = null;private void Form1_Load(object sen der, Eve ntArgs e)/对象初始化mapctrlMai nMap = (IMapC on trol3)this.axMapCo ntrol1.Object;m_ipActiveView = axMapC on trol1.ActiveView;mpMap = mpActiveView.FocusMap;clicked = false;pGC = m_ipMap as IGraphicsC on tai ner;private void Findpath_Click(obje

8、ct sender, EventArgs e)mapctrlMa in Map.Curre ntTool = n ull;/设置鼠标样式axMapCo ntrol1.MousePoi nteresriC on trolsMousePoi nter.esriPoi nterCrosshair;if (axMapCo ntroll.LayerCou nt = 0)MessageBox.Show(请先加载几何网络数据!”);return;m_ipActiveView = axMapC on trol1.ActiveView;mpMap = mpActiveView.FocusMap;clicked

9、= false;pGC = m_ipMap as IGraphicsC on tai ner;ILayeripLayer = m_ipMap.get_Layer(O);IFeatureLayeripFeatureLayer = ipLayer as IFeatureLayer;Ope nF eatureDatasetNetwork(ipFDS);clicked = true;clickedco unt = 0;pGC.DeleteAIIEIeme nts();private void SolvePath_Click(object sen der, Eve ntArgs e)axMapCo nt

10、rol1.MousePoi nteresriCo ntrolsMousePoi nter.esriPoi nterDefault;if (SolvePathGa n(Weight)先解析路径IPolyli neipPolyResult = PathPolyLi ne();最后返回最短路径clicked = false;if (ipPolyResult.lsEmpty)MessageBox.Show(没有路径可到!);elseIRgbColor color = new RgbColorClass();color.Red = 255;color.Blue = 64;color.Green = 12

11、8;Lin eEleme ntClass eleme nt = new Lin eEleme ntClass();ILi neSymbolli nesymbol = new SimpleLi neSymbolClass();lin esymbol.Color = color as IColor;lin esymbol.Width = 3;eleme nt.Geometry = m_ipPolyli ne;eleme nt.Symbol = lin esymbol;pGC.AddEleme nt(eleme nt, 0);mpActiveView.PartialRefresh(esriViewD

12、rawPhase.esriViewGraphics,null, null);axMapC on trol1.FlashShape(eleme nt.Geometry);MessageBox.Show(路径经过+ mpEnumNetEID_Edges.Count + 条线 rn + 经过节点数为+ mpEnumNetEID_Junctions.Count + rn + 路线长度为+ m+ Hrn, 几何路径信息);/路径缩放功能private void SuoFang_Click(object sender, EventArgs e)if (mpPolyli ne = n ull)Message

13、Box.Show(当前没有执行路径查询! !请确认!);elsethis.axMapC on trolI.Exte nt = m_ipPolyli ne.E nv elope;#region自定义路径查询函数voidpublicOpenF eatureDatasetNetwork(IFeatureDatasetFeatureDataset)CloseWorkspace();if (!I nitializeNetworkA ndMap(FeatureDataset)Console.WriteLine(打开 network 出错);/关闭工作空间private void CloseWorkspac

14、e()m_ipGeometricNetwork = n ull;mpPoi nts = n ull;m_ipPo in tToEID = null;m_ipE num NetEID_J un ctio ns = nu II;m_ipE num NetEID_Edges = n ull; m_ipPolyli ne = n ull;/初始化几何网络和地图privatebooll nitializeNetworkA ndMap(IFeatureDatasetFeatureDataset)IFeatureClassCo ntain eripFeatureClassC ontainer;IFeatur

15、eClassipFeatureClass;IGeoDatasetipGeoDataset;ILayeripLayer;IFeatureLayeripFeatureLayer;asIEn velopeipE nvelope, ipMaxE nv elope; doubledblSearchTol;INetworkCollecti oni pNetworkCollecti on= FeatureDatasetINetworkCollectio n;int count = ipNetworkCollectio n.GeometricNetworkCo unt;/获取第一个几何网络工作空间m_ipGe

16、ometricNetworkipNetworkCollectio n.get_GeometricNetwork(O);INetworkipNetwork = m_ipGeometricNetwork.Network;if (m_ipMap != n ull)asipFeatureClassC ontainer=m_ipGeometricNetworkIFeatureClassC ontainer;count = ipFeatureClassC ontain er.ClassCo unt;for (int i = 0; i count; i+)ipFeatureClass = ipFeature

17、ClassC on tai ner.get_Class(i);ipFeatureLayer = new FeatureLayerClass(); ipFeatureLayer.FeatureClass = ipFeatureClass;for (int j = 0; j m_ipMap.LayerCo un t; j+)if(m_ipMap.get_Layer(j).Name.ToUpper()con ti nue;count = m_ipMap.LayerC ount;ipMaxE nvelope = new Env elopeClass();for (int i = 0; i dblHei

18、ght)dblSearchTol = dblWidth / 100;elsedblSearchTol = dblHeight / 100;m_ipPo in tToEID.S napTolera nee = dblSearchTol;return true;/ 返回路径的几何体publicIPolyli nePathPolyLi ne()IEIDI nfoipEIDI nfo;IGeometryipGeometry;if (mpPolyli ne != n ull) return m_ipPolyli ne;asm_ipPolyli ne = new Polyli neClass();IGeo

19、metryCollectio nipNewGeometryColl= m_ipPolyli neIGeometryCollectio n;引用传递ISpatialRefere nceipSpatialRefere nee = m_ipMap.SpatialRefere nee;IEIDHelperipEIDHelper = new EIDHelper(); ipEIDHelper.GeometricNetwork = m_ipGeometricNetwork; ipEIDHelper.OutputSpatialRefere nee = ipSpatialRefere nee; ipEIDHel

20、per.Retur nGeometries = true;IEn umEIDI nfoipE nu mEIDI nfoipEIDHelper.CreateE nu mEIDI nfo(mpEnum NetEID_Edges);int count = ipE nu mEID In fo.Co unt;ipE nu mEIDI nfo.Reset();for (int i = 0; i count; i+)stri ng info;info = new stri ngco un t;ipEIDI nfo = ipE numEIDI nfo.Next();asipGeometry = ipEIDI

21、nfo.Geometry; ipNewGeometryColl.AddGeometryCollect ion (ipGeometry IGeometryCollectio n);in foi = m_ipPolyli ne.Len gth.ToStri ng();returnm_ipPolyli ne;publicboolSolvePathGa n(stri ng WeightName)tryintintJunction UserClassID; in ti ntJunction UserID; intintJunction UserSubID;intintJunction ID;IPo in

22、 tipF oundJun cti onPoint;asITraceFlowSolverGENipTraceFlowSolver = new TraceFlowSolver()ITraceFlowSolverGEN;INetSolveripNetSolver = ipTraceFlowSolver as INetSolver;if (m_ipGeometricNetwork = n ull)return false;INetworkipNetwork = m_ipGeometricNetwork.Network;ipNetSolver.SourceNetwork = ipNetwork;INe

23、tEleme ntsipNetEleme nts = ipNetwork as INetEleme nts;if (mpPoi nts = n ull) MessageBox.Show(”请选择点!); return false; intintCount = mpPoints.PointCount;这里的 points 有值吗?/定义一个边线旗数组最近点*/Jun cti onF lag pJunctionF lagList = new Jun ctio nF lagi ntCo unt;for (i nt i = 0; i in tCo unt; i+)INetFlagipNetFlag =

24、 new JunctionF lag() as INetFlag;IPo in tipJ unctionPoint = mpPoi nts.get_Poi nt(i);/查找输入点的最近的网络点m_ipPoi ntToEID.GetNearestJ un ctio n(ipJ un ctio nPoi nt,outintJun cti on ID, out ipF oundJun cti onPoin t);ipNetEleme nts.QueryIDs(i ntJ un ctio nID,esriEleme ntType.esriETJ un cti on,out intJunction U

25、serClassID,outintJun cti on UserID, out intJunction UserSubID);ipNetFlag.UserClassID = in tJu nctio nUserClassID;ipNetFlag.UserlD = in tJu nctio nUserlD;ipNetFlag.UserSublD = in tJu nctio nUserSublD;IJun cti onF lagpTemp = (IJ un cti onF lag)(ipNetFlag as IJun cti onF lag);pJun cti onF lagListi = pT

26、emp;ipTraceFlowSolver.PutJ un ctio nOrigi ns(ref pJunctionF lagList);INetSchemaipNetSchema = ipNetwork as INetSchema;INetWeightipNetWeight = ipNetSchema.get_WeightByName(WeightName);INetSolverWeightsipNetSolverWeights= ipTraceFlowSolver asINetSolverWeights;ipNetSolverWeights.FromToEdgeWeight = ipNet

27、Weight;/开始边线的权重ipNetSolverWeights.ToFromEdgeWeight = ipNetWeight;/终止边线的权重object vaRes = new objecti ntCo unt - 1;/通过findpath得到边线和交汇点的集合ipTraceFlowSolver.F in dPath(esriFlowMethod.esriFMC onn ected, esriShortestPathObjF n.esriSPObjF nMin Sum,outmpEnum NetEID_Ju nctio ns, out m_ipE num NetEID_Edges, i

28、n tCo unt - 1, ref vaRes);m_dblPathCost = 0;for (int i = 0; i vvaRes.Le ngth; i+)doublem_Va = (double)vaResi; m_dblPathCost = m_dblPathCost + m_Va;m_ipPolyli ne = n ull;return true;catch (Exceptio n ex)Con sole.WriteLi ne(ex.Message); return false;#en dregi onsen der,privatevoidaxMapC on trol1_O nM

29、ouseDow n(o bjectIMap Co ntrolEve nts2_ On MouseDow nEve nt e)if (clicked != true)return;IPoi ntipNew;if (mpPoi nts = n ull)mpPoi nts = new Multipoi nt();ipNewmpActiveView.Scree nDisplay.DisplayTra nsformatio n.ToMapPoi nt(e.x,e.y);object o = Type.Miss ing;m_ipPoi nts.AddPoi nt(ipNew, ref o, ref o);

30、IEleme nt eleme nt;ITextEleme nttexteleme nt = new TextEleme ntClass();eleme nt = texteleme nt as IEleme nt;clickedco un t+;texteleme nt.Text = clickedco un t.ToStri ng();eleme nt.GeometrympActiveView.Scree nDisplay.DisplayTra nsformatio n.ToMapPoi nt(e.x,e.y);pGC.AddEleme nt(eleme nt, 0);m_ipActive

31、View.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);3.4实验结果在得到的窗口中加载“甘地的个人地理数据库”(在压缩包中有)中的几何网络“ road_Net ”,将几何网络地图加载到地图显示窗口中,如下图所示:jpln.dj twfr 实可亠* x S步色氨Q0針而llhgL=Je II 站 Iej童擬膏莎忑J霑s&H倉ra回1打开|aL1 SizpprteiiJ电消t td r=d _*! .Arrliowi点击图标添加起始点,效果如下图然后点击图标X,计算最短路径,效果如下图:几伺賂MLI蛊径经过25矽 经

32、过节点堆茁 蹈显废为200弟魂4$最后点击图标得到最短路径的缩放,效果如下图:这样就完成了最短路径的查询分析和显示的功能4、实习总结在整个过程中所出现的问题较多,体现出个人基础的不足,程序的出错有时候出现在标点符号以及英文字母的大小写上面等等问题,这些都说明了不熟练的问题。因此,二次开发的一个最重要的是勤于练习敲代码, 能够对着书本的代码 敲二不会出现一些不该犯的错误,然后进行下一步的提高,一步一个踏实的脚印, 打下一个坚实的基础是非常重要。另一个重要的体会就是学会自己去查询资料, 尽可能的通过自己的能力解决问题,实在不能解决的在向老师请教,这是在大学 中一个重要的方法,因此学会独立去解决问题通过查询资料, 虽然是一个困难重 重的过程,但是能够学到好多有用的能力。

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1