您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 交通运输 > GIS软件工程实习报告(最短路径分析)
AE开发之基于几何网络的最短路径分析1、实习目的本次实习目的在于熟练掌握ArcGISEngine开发工具并能够通过C#语言在VS2010开发环境中完成查询几何网络的最短路径分析的功能。2、实习时间2015年5月23日星期六3、实习内容3.1实验环境操作系统:Windows2007二次开发平台:VS2010开发环境、ArcGISDesktop10.0、AE开发组件3.2实验任务完成基于几何网络分析的最短路径查询功能,即实现通过在几何网络地图中指定起始点,能够查询经过起始点的最短路线,并能够通过缩放功能在地图窗口居中显示。3.3实验步骤3.3.1新建项目选择\文件\新建项目,如图选择项目类型中VisualC#,再选择WindowsApplication,记为“FindShortPath”,点击确定。3.3.2添加控件3.3.3控件绑定因为添加的控件只是单独存在,但是程序需要各控件间协同工作,因此要进行控件绑定。3.3.4创建几何网络1.在ArcCataLog中新建个人地理数据库—“甘地的个人地理数据库”,然后新建要素数据集“road”,接着,鼠标右键选择要素数据集“road”,选择“导入要素类”,导入需要创建几何网络的要素类“主要公路”,输出要素类的名字改为“road”,如下图所示:2.鼠标右键选择要素数据集“road”,选择新建“几何网络”,则出现“新建几何网络”对话框,作如下图所示的一系列设置,最终得到几何网络“road_Net”。至此,得到几何网络“road_Net”,如下图所示:3.3.5代码实现最短路径分析①设置ToolStrip1②添加代码privateIActiveViewm_ipActiveView;privateIMapm_ipMap;//地图控件中地图privateIGraphicsContainerpGC;//图形对象privateboolclicked=false;intclickedcount=0;privatedoublem_dblPathCost=0;privateIGeometricNetworkm_ipGeometricNetwork;privateIPointCollectionm_ipPoints;//输入点集合privateIPointToEIDm_ipPointToEID;privateIEnumNetEIDm_ipEnumNetEID_Junctions;privateIEnumNetEIDm_ipEnumNetEID_Edges;privateIPolylinem_ipPolyline;privateIMapControl3mapctrlMainMap=null;privatevoidForm1_Load(objectsender,EventArgse){//对象初始化mapctrlMainMap=(IMapControl3)this.axMapControl1.Object;m_ipActiveView=axMapControl1.ActiveView;m_ipMap=m_ipActiveView.FocusMap;clicked=false;pGC=m_ipMapasIGraphicsContainer;}privatevoidFindpath_Click(objectsender,EventArgse){mapctrlMainMap.CurrentTool=null;//设置鼠标样式axMapControl1.MousePointer=esriControlsMousePointer.esriPointerCrosshair;if(axMapControl1.LayerCount==0){MessageBox.Show(请先加载几何网络数据!);return;}m_ipActiveView=axMapControl1.ActiveView;m_ipMap=m_ipActiveView.FocusMap;clicked=false;pGC=m_ipMapasIGraphicsContainer;ILayeripLayer=m_ipMap.get_Layer(0);IFeatureLayeripFeatureLayer=ipLayerasIFeatureLayer;IFeatureDatasetipFDS=ipFeatureLayer.FeatureClass.FeatureDataset;OpenFeatureDatasetNetwork(ipFDS);clicked=true;clickedcount=0;pGC.DeleteAllElements();}privatevoidSolvePath_Click(objectsender,EventArgse){axMapControl1.MousePointer=esriControlsMousePointer.esriPointerDefault;if(SolvePathGan(Weight))//先解析路径{IPolylineipPolyResult=PathPolyLine();//最后返回最短路径clicked=false;if(ipPolyResult.IsEmpty){MessageBox.Show(没有路径可到!!);}else{IRgbColorcolor=newRgbColorClass();color.Red=255;color.Blue=64;color.Green=128;LineElementClasselement=newLineElementClass();ILineSymbollinesymbol=newSimpleLineSymbolClass();linesymbol.Color=colorasIColor;linesymbol.Width=3;element.Geometry=m_ipPolyline;element.Symbol=linesymbol;pGC.AddElement(element,0);m_ipActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics,null,null);axMapControl1.FlashShape(element.Geometry);MessageBox.Show(路径经过+m_ipEnumNetEID_Edges.Count+条线+\r\n+经过节点数为+m_ipEnumNetEID_Junctions.Count+\r\n+路线长度为+m_ipPolyline.Length.ToString(#######.##)+\r\n,几何路径信息);}}}//路径缩放功能privatevoidSuoFang_Click(objectsender,EventArgse){if(m_ipPolyline==null){MessageBox.Show(当前没有执行路径查询!!!请确认!);}else{this.axMapControl1.Extent=m_ipPolyline.Envelope;}}#region自定义路径查询函数publicvoidOpenFeatureDatasetNetwork(IFeatureDatasetFeatureDataset){CloseWorkspace();if(!InitializeNetworkAndMap(FeatureDataset))Console.WriteLine(打开network出错);}//关闭工作空间privatevoidCloseWorkspace(){m_ipGeometricNetwork=null;m_ipPoints=null;m_ipPointToEID=null;m_ipEnumNetEID_Junctions=null;m_ipEnumNetEID_Edges=null;m_ipPolyline=null;}//初始化几何网络和地图privateboolInitializeNetworkAndMap(IFeatureDatasetFeatureDataset){IFeatureClassContaineripFeatureClassContainer;IFeatureClassipFeatureClass;IGeoDatasetipGeoDataset;ILayeripLayer;IFeatureLayeripFeatureLayer;IEnvelopeipEnvelope,ipMaxEnvelope;doubledblSearchTol;INetworkCollectionipNetworkCollection=FeatureDatasetasINetworkCollection;intcount=ipNetworkCollection.GeometricNetworkCount;//获取第一个几何网络工作空间m_ipGeometricNetwork=ipNetworkCollection.get_GeometricNetwork(0);INetworkipNetwork=m_ipGeometricNetwork.Network;if(m_ipMap!=null){ipFeatureClassContainer=m_ipGeometricNetworkasIFeatureClassContainer;count=ipFeatureClassContainer.ClassCount;for(inti=0;icount;i++){ipFeatureClass=ipFeatureClassContainer.get_Class(i);ipFeatureLayer=newFeatureLayerClass();ipFeatureLayer.FeatureClass=ipFeatureClass;for(intj=0;jm_ipMap.LayerCount;j++){if(m_ipMap.get_Layer(j).Name.ToUpper()==ipFeatureLayer.Name.ToUpper()){continue;}}}}count=m_ipMap.LayerCount;ipMaxEnvelope=newEnvelopeClass();for(inti=0;icount;i++){ipLayer=m_ipMap.get_Layer(i);ipFeatureLayer=ipLayerasIFeatureLayer;ipGeoDataset=ipFeatureLayerasIGeoDataset;ipEnvelope=ipGeoDataset.Extent;ipMaxEnvelope.Union(ipEnvelope);}m_ipPointToEID=newPointToEIDClass();m_ipPointToEID.SourceMap=m_ipMap;m_ipPointToEID.GeometricNetwork=m_ipGeometricNetwork;doubledblWidth=ipMaxEnvelope.Width;doubledblHeight=ipMaxEnvelope.Height;if(dblWidthdblHeight)dblSearchTol=dblWidth/100;elsedblSearchTol=dblHeight/100;m_ipPointToEID.SnapTolerance=dblSearchTol;returntrue;}//返回路径的几何体publicIPolylinePathPolyLine(){IEIDInfoipEIDInfo;IGeometryipGeometry;if(m_ipPolyline!=null)returnm_ipPolyline;m_ipPolyline=newPolylineClass();IGeometryCollectionipNe
本文标题:GIS软件工程实习报告(最短路径分析)
链接地址:https://www.777doc.com/doc-2874162 .html