最短路径分析_第1页
最短路径分析_第2页
最短路径分析_第3页
最短路径分析_第4页
最短路径分析_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

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

文档简介

1、最短路径分析(源码)namespace GisEditor/ <summary>/ 最短路径分析/ </summary>public class ClsPathFinder   private IGeometricNetwork m_ipGeometricNetwork;   private IMap m_ipMap;   private IPointCollection m_ipPoints;   private IPointToEID m_ipPointToEID;  

2、; private double m_dblPathCost =0;   private IEnumNetEID m_ipEnumNetEID_Junctions;   private IEnumNetEID m_ipEnumNetEID_Edges;   private IPolyline    m_ipPolyline;   #region Public Function   /返回和设置当前地图   public IMap SetOrGet

3、Map        set m_ipMap = value;    getreturn    m_ipMap;      /打开几何数据集的网络工作空间   public void OpenFeatureDatasetNetwork(IFeatureDataset FeatureDataset)       CloseWorkspace();   

4、;    if (!InitializeNetworkAndMap(FeatureDataset)     Console.WriteLine( "打开network出错");      /输入点的集合   public IPointCollection StopPoints       setm_ipPoints= value;    getreturn 

5、   m_ipPoints;         /路径成本   public double PathCost       get return m_dblPathCost;        /返回路径的几何体   public IPolyline PathPolyLine()       IEIDInfo ipE

6、IDInfo;    IGeometry ipGeometry;        if(m_ipPolyline!=null)return m_ipPolyline;       m_ipPolyline = new PolylineClass();    IGeometryCollection ipNewGeometryColl = m_ipPolyline as IGeometryCollection;&

7、#160;      ISpatialReference ipSpatialReference = m_ipMap.SpatialReference;    IEIDHelper ipEIDHelper = new EIDHelperClass();    ipEIDHelper.GeometricNetwork = m_ipGeometricNetwork;      ipEIDHelper.OutputSpatialReferenc

8、e = ipSpatialReference;    ipEIDHelper.ReturnGeometries = true;    IEnumEIDInfo ipEnumEIDInfo = ipEIDHelper.CreateEnumEIDInfo(m_ipEnumNetEID_Edges);    int count = ipEnumEIDInfo.Count;    ipEnumEIDInfo.Reset();    for(int i =

9、0;i<count;i+)         ipEIDInfo = ipEnumEIDInfo.Next();     ipGeometry = ipEIDInfo.Geometry;     ipNewGeometryColl.AddGeometryCollection( ipGeometry as IGeometryCollection);        return m_ip

10、Polyline;        /解决路径   public void SolvePath(string WeightName)       try            int intEdgeUserClassID;     int intEdgeUserID;     int int

11、EdgeUserSubID;     int intEdgeID;     IPoint ipFoundEdgePoint;     double dblEdgePercent;          /*PutEdgeOrigins方法的第二个参数要求是IEdgeFlag类型的数组,      * 在VB等其他语言的代码中,只需传人该类型数

12、组的第一个元素即      * 可,但C#中的机制有所不同,需要作出如下修改:使用      * ITraceFlowSolverGEN替代ITraceFlowSolver      */     ITraceFlowSolverGEN   ipTraceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN;

13、0;    INetSolver ipNetSolver = ipTraceFlowSolver as INetSolver;     INetwork ipNetwork = m_ipGeometricNetwork.Network;     ipNetSolver.SourceNetwork = ipNetwork;     INetElements ipNetElements = ipNetwork as INetElements;

14、0;    int intCount = m_ipPoints.PointCount;     /定义一个边线旗数组     IEdgeFlag pEdgeFlagList = new EdgeFlagClassintCount;     for(int i = 0;i<intCount ;i+)             

15、    INetFlag ipNetFlag = new EdgeFlagClass()as INetFlag;      IPoint   ipEdgePoint = m_ipPoints.get_Point(i);      /查找输入点的最近的边线      m_ipPointToEID.GetNearestEdge(ipEdgePoint, out intEdgeID,out ipFoun

16、dEdgePoint, out dblEdgePercent);      ipNetElements.QueryIDs( intEdgeID, esriElementType.esriETEdge, out intEdgeUserClassID, out intEdgeUserID,out intEdgeUserSubID);      ipNetFlag.UserClassID = intEdgeUserClassID;      ipNet

17、Flag.UserID = intEdgeUserID;      ipNetFlag.UserSubID = intEdgeUserSubID;       IEdgeFlag pTemp = (IEdgeFlag)(ipNetFlag as IEdgeFlag);      pEdgeFlagListi=pTemp;           

18、60;  ipTraceFlowSolver.PutEdgeOrigins(ref pEdgeFlagList);     INetSchema ipNetSchema = ipNetwork as INetSchema;     INetWeight ipNetWeight = ipNetSchema.get_WeightByName(WeightName);     INetSolverWeights ipNetSolverWeights = ipTraceFl

19、owSolver as INetSolverWeights;     ipNetSolverWeights.FromToEdgeWeight = ipNetWeight;/开始边线的权重     ipNetSolverWeights.ToFromEdgeWeight = ipNetWeight;/终止边线的权重     object vaRes =new objectintCount-1;     /通过findpath得到边线和交汇点

20、的集合     ipTraceFlowSolver.FindPath(esriFlowMethod.esriFMConnected,      esriShortestPathObjFn.esriSPObjFnMinSum,      out m_ipEnumNetEID_Junctions,out m_ipEnumNetEID_Edges, intCount-1, ref vaRes);      /计算元素成本&

21、#160;    m_dblPathCost = 0;     for (int i =0;i<vaRes.Length;i+)           double m_Va =(double) vaResi;      m_dblPathCost = m_dblPathCost + m_Va;        &#

22、160;      m_ipPolyline = null;         catch(Exception ex)         Console.WriteLine(ex.Message);          #endregion   #region Private Function   /初始化几何网络

23、和地图   private bool InitializeNetworkAndMap(IFeatureDataset FeatureDataset)       IFeatureClassContainer ipFeatureClassContainer;    IFeatureClass ipFeatureClass ;    IGeoDataset ipGeoDataset;    ILayer ipLayer ; 

24、60;  IFeatureLayer ipFeatureLayer;    IEnvelope ipEnvelope, ipMaxEnvelope ;    double dblSearchTol;    INetworkCollection ipNetworkCollection = FeatureDataset as INetworkCollection;    int count = ipNetworkCollection.GeometricNetworkCo

25、unt;    /获取第一个几何网络工作空间    m_ipGeometricNetwork = ipNetworkCollection.get_GeometricNetwork(0);    INetwork ipNetwork = m_ipGeometricNetwork.Network;    if(m_ipMap!=null)         m_ipMap = new MapClass();

26、60;    ipFeatureClassContainer = m_ipGeometricNetwork as IFeatureClassContainer;     count = ipFeatureClassContainer.ClassCount;     for(int i =0;i<count;i+)           ipFeatureClass = ipFeatureCla

27、ssContainer.get_Class(i);            ipFeatureLayer = new FeatureLayerClass();      ipFeatureLayer.FeatureClass = ipFeatureClass;           m_ipMap.AddLayer( ipFeatureLay

28、er);             count = m_ipMap.LayerCount;    ipMaxEnvelope = new EnvelopeClass();    for(int i =0;i<count;i+)         ipLayer = m_ipMap.get_Layer(i);     ipFea

29、tureLayer = ipLayer as IFeatureLayer;         ipGeoDataset = ipFeatureLayer as IGeoDataset;     ipEnvelope = ipGeoDataset.Extent;         ipMaxEnvelope.Union( ipEnvelope);        m_ipPointToEID = new PointToEIDClass();    m_ipPointToEID.SourceMap = m_ipMap;    m_ipPointToEID.GeometricNetwork = m_ipGeometricNetwork;    double dblWidth = ipMaxEnvelope.W

温馨提示

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

评论

0/150

提交评论