A*算法的最短路径实现!

  1.   #region A_STAR 
  2.         public  IRgbColor getRGB(int r,int g,int b)//用于获取颜色
  3.         {
  4.             IRgbColor pColor;
  5.             pColor = new RgbColorClass();
  6.             pColor.Red = r;
  7.             pColor.Green = g;
  8.             pColor.Blue = b;
  9.             return pColor;
  10.         }
  11.         //定义路网中的边信息
  12.         public class Edge
  13.         {
  14.             public string EdgeFID;
  15.             public string StartNodeID;
  16.             public string EndNodeID;
  17.             public double Weight; //权值,代价        
  18.         }
  19.         //定义路网中的点信息
  20.         public class NETA_Point
  21.         {
  22.             private string pointID;
  23.             private double fn;
  24.             private double gn;
  25.             private double hn;
  26.             private bool isEnabled;
  27.             private PointAnalyseState analyseState;
  28.             private double x;
  29.             private double y;
  30.             //定义父结点
  31.             private NETA_Point parentPoint;
  32.             private ArrayList edgeList;//Edge的集合--出边表
  33.             public NETA_Point()
  34.             {
  35.             }
  36.             //构造函数初始化
  37.             public NETA_Point(string id)
  38.             {
  39.                 this.pointID = id;
  40.                 this.fn = 0;
  41.                 this.gn = 0;
  42.                 this.hn = 0;
  43.                 this.isEnabled = true;
  44.                 this.analyseState = PointAnalyseState.Undisposed;
  45.                 this.x = 0;
  46.                 this.y = 0;
  47.                 this.parentPoint = new NETA_Point();
  48.                 this.edgeList = new ArrayList();
  49.             }
  50.             #region property
  51.             public string PointID
  52.             {
  53.                 get
  54.                 {
  55.                     return this.pointID;
  56.                 }
  57.             }
  58.             public double Fn
  59.             {
  60.                 get
  61.                 {
  62.                     return this.fn;
  63.                 }
  64.                 set
  65.                 {
  66.                     this.fn = value;
  67.                 }
  68.             }
  69.             public double Gn
  70.             {
  71.                 get
  72.                 {
  73.                     return this.gn;
  74.                 }
  75.                 set
  76.                 {
  77.                     this.gn = value;
  78.                 }
  79.             }
  80.             public double Hn
  81.             {
  82.                 get
  83.                 {
  84.                     return this.hn;
  85.                 }
  86.                 set
  87.                 {
  88.                     this.hn = value;
  89.                 }
  90.             }
  91.             public double X
  92.             {
  93.                 get
  94.                 {
  95.                     return this.x;
  96.                 }
  97.                 set
  98.                 {
  99.                     this.x = value;
  100.                 }
  101.             }
  102.             public double Y
  103.             {
  104.                 get
  105.                 {
  106.                     return this.y;
  107.                 }
  108.                 set
  109.                 {
  110.                     this.y = value;
  111.                 }
  112.             }
  113.             public PointAnalyseState AnalyseState
  114.             {
  115.                 get
  116.                 {
  117.                     return this.analyseState;
  118.                 }
  119.                 set
  120.                 {
  121.                     this.analyseState = value;
  122.                 }
  123.             }
  124.             public bool IsEnabled
  125.             {
  126.                 get
  127.                 {
  128.                     return this.isEnabled;
  129.                 }
  130.             }
  131.             public NETA_Point ParentPoint
  132.             {
  133.                 get
  134.                 {
  135.                     return this.parentPoint;
  136.                 }
  137.                 set
  138.                 {
  139.                     this.parentPoint = value;
  140.                 }
  141.             }
  142.             public ArrayList EdgeList
  143.             {
  144.                 get
  145.                 {
  146.                     return this.edgeList;
  147.                 }
  148.             }
  149.             #endregion
  150.         }
  151.         public enum PointAnalyseState
  152.         {
  153.             InOpenList,
  154.             InCloseList,
  155.             Undisposed
  156.         }
  157.         private void printPath(ArrayList strPath) //显示线路
  158.         {
  159.            
  160.             IMap pMap = axMapControl1.Map;
  161.             IActiveView pActiveView = pMap as IActiveView;
  162.             IFeatureLayer pFeatureLayer = pMap.get_Layer(1) as IFeatureLayer;
  163.             IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
  164.             IQueryFilter pQueryFilter = new QueryFilterClass();
  165.             ISimpleLineSymbol pLineSymbol = new SimpleLineSymbolClass();
  166.             pLineSymbol.Color = getRGB(100, 100, 255);
  167.             pLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
  168.             pLineSymbol.Width = 3;
  169.             
  170.             foreach (string s in strPath)
  171.             {
  172.                                
  173.                 pQueryFilter.WhereClause = "FID_1=" + s + "";
  174.                 IFeatureCursor pCursor = pFeatureClass.Search(pQueryFilter, false);
  175.                 IFeature pFeature = pCursor.NextFeature();
  176.                 IPolyline pPolyline = pFeature.Shape as IPolyline;
  177.                 ILineElement pLineElement = new LineElementClass();
  178.                 IElement m_Element;
  179.                 
  180.                 m_Element = pLineElement as IElement;
  181.               
  182.                 m_Element.Geometry = pPolyline;
  183.                 pLineElement.Symbol = pLineSymbol;
  184.                 IGraphicsContainer pgc = pMap as IGraphicsContainer;
  185.                 pgc.AddElement(pLineElement as IElement, 0);
  186.                 
  187.             }
  188.             pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, nullnull);
  189.         }
  190.         private void printPath2(ArrayList strPath)//利用选择集
  191.         {
  192.             IMap pMap = axMapControl1.Map;
  193.             IActiveView pActiveView = pMap as IActiveView;
  194.             IFeatureLayer pFeatLayer = pMap.get_Layer(1) as IFeatureLayer;
  195.             IQueryFilter pQueryFilter = new QueryFilterClass();
  196.             IFeatureClass pFeatClass = pFeatLayer.FeatureClass;
  197.             foreach (string pathName in strPath)
  198.             {
  199.                 pQueryFilter.WhereClause = "FID_1 =" + pathName + "";
  200.                 IFeatureCursor pFeatCursor = pFeatClass.Search(pQueryFilter, false);
  201.                 IFeature pFeat = pFeatCursor.NextFeature();
  202.                 pMap.SelectFeature(pFeatLayer, pFeat);
  203.             }
  204.             pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, nullnull);    
  205.         }
  206.         
  207.         #region 二叉堆数据结构,用于OpenList结构
  208.         //针对A*算法设计的二叉堆结构,用于OpenList结构
  209.         //KeyID对应PtID,所以唯一
  210.         //Fn可能重复
  211.         //按Fn维护堆结构
  212.         //zhb 2008.11.4
  213.         public class BinaryHeapItem
  214.         {
  215.             public Double Fn;
  216.             public string KeyID;
  217.         }
  218.         //二叉堆接口定义
  219.         public interface iNETA_BinaryHeapM
  220.         {
  221.             bool AddItem(BinaryHeapItem Item);
  222.             bool MinishItemFnValue(string KeyID, Double NewFn);//A*应用中只会减小Fn
  223.             BinaryHeapItem GetAndRemoveMinFnItem();
  224.             void Clear();
  225.             int ItemCount { get;}
  226.         }
  227.         //Singleton二叉堆接口的函数实现
  228.         public class NETA_BinaryHeap : iNETA_BinaryHeapM
  229.         {
  230.             public static readonly NETA_BinaryHeap NETA_BinaryHeapInstance = new NETA_BinaryHeap();
  231.             private System.Collections.Hashtable BinaryHeap = new System.Collections.Hashtable();
  232.             private NETA_BinaryHeap() { }
  233.             #region iNETA_BinaryHeapM 成员
  234.             #region AddItem增加新成员
  235.             public bool AddItem(BinaryHeapItem Item)
  236.             {
  237.                 try
  238.                 {
  239.                     if (BinaryHeap.Count == 0)
  240.                         BinaryHeap.Add(1, Item);
  241.                     else
  242.                     {
  243.                         BinaryHeap.Add(BinaryHeap.Count + 1, Item);
  244.                         int index = BinaryHeap.Count;
  245.                         int temp;
  246.                         double temp1;
  247.                         BinaryHeapItem tempItem;
  248.                         bool isOK = false;
  249.                         while (!isOK)
  250.                         {
  251.                             temp1 = index / 2;
  252.                             temp = (int)System.Math.Floor(temp1);
  253.                             if (temp <= 0) break;
  254.                             if (((BinaryHeapItem)BinaryHeap[temp]).Fn > ((BinaryHeapItem)BinaryHeap[index]).Fn)
  255.                             {
  256.                                 tempItem = (BinaryHeapItem)BinaryHeap[temp];
  257.                                 BinaryHeap[temp] = (BinaryHeapItem)BinaryHeap[index];
  258.                                 BinaryHeap[index] = tempItem;
  259.                                 index = temp;
  260.                             }
  261.                             else
  262.                                 isOK = true;
  263.                         }
  264.                     }
  265.                     return true;
  266.                 }
  267.                 catch (Exception e)
  268.                 {
  269.                     MessageBox.Show("NETA_BinaryHeap.AddItem错误" + e.Message);
  270.                     return false;
  271.                 }
  272.             }
  273.             #endregion
  274.             //删除成员,并返回最小值
  275.             public BinaryHeapItem GetAndRemoveMinFnItem()
  276.             {
  277.                 try
  278.                 {
  279.                     if (BinaryHeap.ContainsKey(1))
  280.                     {
  281.                         BinaryHeapItem ResultItem = (BinaryHeapItem)BinaryHeap[1];
  282.                         BinaryHeapItem ChangeItem = (BinaryHeapItem)BinaryHeap[BinaryHeap.Count];
  283.                         BinaryHeap.Remove(BinaryHeap.Count);
  284.                         if (BinaryHeap.Count == 0) return ResultItem;
  285.                         BinaryHeap[1] = ChangeItem;
  286.                         int index = 1;
  287.                         int temp;
  288.                         BinaryHeapItem tempItem;
  289.                         bool isOK = false;
  290.                         while (!isOK)
  291.                         {
  292.                             temp = index * 2;
  293.                             if (temp + 1 <= BinaryHeap.Count)
  294.                             {
  295.                                 if ((((BinaryHeapItem)BinaryHeap[index]).Fn > ((BinaryHeapItem)BinaryHeap[temp]).Fn) && (((BinaryHeapItem)BinaryHeap[index]).Fn > ((BinaryHeapItem)BinaryHeap[temp + 1]).Fn))
  296.                                 {
  297.                                     if (((BinaryHeapItem)BinaryHeap[temp]).Fn <= ((BinaryHeapItem)BinaryHeap[temp + 1]).Fn)
  298.                                     {
  299.                                         tempItem = (BinaryHeapItem)BinaryHeap[temp];
  300.                                         BinaryHeap[temp] = (BinaryHeapItem)BinaryHeap[index];
  301.                                         BinaryHeap[index] = tempItem;
  302.                                         index = temp;
  303.                                     }
  304.                                     else
  305.                                     {
  306.                                         tempItem = (BinaryHeapItem)BinaryHeap[temp + 1];
  307.                                         BinaryHeap[temp + 1] = (BinaryHeapItem)BinaryHeap[index];
  308.                                         BinaryHeap[index] = tempItem;
  309.                                         index = temp + 1;
  310.                                     }
  311.                                 }
  312.                                 else if (((BinaryHeapItem)BinaryHeap[index]).Fn > ((BinaryHeapItem)BinaryHeap[temp]).Fn)
  313.                                 {
  314.                                     tempItem = (BinaryHeapItem)BinaryHeap[temp];
  315.                                     BinaryHeap[temp] = (BinaryHeapItem)BinaryHeap[index];
  316.                                     BinaryHeap[index] = tempItem;
  317.                                     index = temp;
  318.                                 }
  319.                                 else if (((BinaryHeapItem)BinaryHeap[index]).Fn > ((BinaryHeapItem)BinaryHeap[temp + 1]).Fn)
  320.                                 {
  321.                                     tempItem = (BinaryHeapItem)BinaryHeap[temp + 1];
  322.                                     BinaryHeap[temp + 1] = (BinaryHeapItem)BinaryHeap[index];
  323.                                     BinaryHeap[index] = tempItem;
  324.                                     index = temp + 1;
  325.                                 }
  326.                                 else
  327.                                     isOK = true;
  328.                             }
  329.                             else if ((temp == BinaryHeap.Count) && (((BinaryHeapItem)BinaryHeap[index]).Fn > ((BinaryHeapItem)BinaryHeap[temp]).Fn))
  330.                             {
  331.                                 tempItem = (BinaryHeapItem)BinaryHeap[temp];
  332.                                 BinaryHeap[temp] = (BinaryHeapItem)BinaryHeap[index];
  333.                                 BinaryHeap[index] = tempItem;
  334.                                 index = temp;
  335.                             }
  336.                             else
  337.                                 break;
  338.                         }
  339.                         return ResultItem;
  340.                     }
  341.                     else
  342.                         return null;
  343.                 }
  344.                 catch (Exception e)
  345.                 {
  346.                     MessageBox.Show("NETA_BinaryHeap.GetMinFnItem错误" + e.Message);
  347.                     return null;
  348.                 }
  349.             }
  350.             //更新Openlist中的Fn值。
  351.             public bool MinishItemFnValue(string KeyID, double NewFn)
  352.             {
  353.                 try
  354.                 {
  355.                     int index = -1;
  356.                     int temp;
  357.                     Double temp1;
  358.                     BinaryHeapItem tempItem;
  359.                     bool isOK = false;
  360.                     foreach (DictionaryEntry myDE in BinaryHeap)
  361.                     {
  362.                         if (((BinaryHeapItem)myDE.Value).KeyID == KeyID)
  363.                         {
  364.                             //A*应用中只能减小Fn
  365.                             if (((BinaryHeapItem)myDE.Value).Fn <= NewFn) return false;//非法Fn
  366.                             ((BinaryHeapItem)myDE.Value).Fn = NewFn;
  367.                             index = (int)(myDE.Key);
  368.                             break;
  369.                         }
  370.                     }
  371.                     if (index == -1) return false;
  372.                     while (!isOK)
  373.                     {
  374.                         temp1 = index / 2;
  375.                         temp = (int)System.Math.Floor(temp1);
  376.                         if (temp <= 0) break;
  377.                         if (((BinaryHeapItem)BinaryHeap[temp]).Fn > ((BinaryHeapItem)BinaryHeap[index]).Fn)
  378.                         {
  379.                             tempItem = (BinaryHeapItem)BinaryHeap[temp];
  380.                             BinaryHeap[temp] = (BinaryHeapItem)BinaryHeap[index];
  381.                             BinaryHeap[index] = tempItem;
  382.                             index = temp;
  383.                         }
  384.                         else
  385.                             isOK = true;
  386.                     }
  387.                     return true;
  388.                 }
  389.                 catch (Exception e)
  390.                 {
  391.                     MessageBox.Show("NETA_BinaryHeap.MinishItemFnValue错误" + e.Message);
  392.                     return false;
  393.                 }
  394.             }
  395.             public int ItemCount
  396.             {
  397.                 get { return BinaryHeap.Count; }
  398.             }
  399.             public void Clear()
  400.             {
  401.                 BinaryHeap.Clear();
  402.             }
  403.             #endregion
  404.         }
  405.         #endregion
  406.         #region 辅助类的定义
  407.         //接口,对查找最短路径的功能进行定义
  408.         public interface iNetShortPathAnalyse
  409.         {
  410.             NETA_Point NetShortPathAnalyse(string StartID, string EndID);
  411.             ArrayList resultPointLine(string start, string end);
  412.             double ComputeTheHnValue(NETA_Point currPt, NETA_Point EndPt);
  413.             double doCompute(NETA_Point currPt, NETA_Point EndPt);
  414.            
  415.         }
  416.         
  417.         
  418.         public class NETA_NET
  419.         {
  420.             public ArrayList pArraylistRoad = new ArrayList();
  421.             
  422.             public NETA_NET() 
  423.             {
  424.                 pArraylistRoad = pArrayList;
  425.             }
  426.             public NETA_Point GetPoint(string PointID)//在路网中获取指定点。
  427.             {
  428.                 //在路网中获取指定点。
  429.                 NETA_Point tempPoint = new NETA_Point();
  430.                 int tag=0;
  431.                 bool getOK = false;
  432.                 for (int i = 0; i < pArraylistRoad.Count; i++)
  433.                 {
  434.                     if (((NETA_Point)pArraylistRoad[i]).PointID == PointID)
  435.                     {
  436.                         tag = i;
  437.                         getOK = true;
  438.                     }
  439.                     
  440.                 }
  441.                 if (getOK)
  442.                 {
  443.                     tempPoint = (NETA_Point)pArraylistRoad[tag];
  444.                 }
  445.                 else
  446.                 {
  447.                     return null;
  448.                 }
  449.                 return tempPoint;
  450.             }
  451.             public ArrayList GetChildrenPoints(NETA_Point currPt)//找出当前点的子点。
  452.             {
  453.                 //找出当前点的子点。
  454.                 ArrayList tempArraylist = new ArrayList();
  455.                 NETA_Point tempPoint = new NETA_Point();
  456.                 foreach (Edge temp in currPt.EdgeList)
  457.                 {
  458.                     if (GetPoint(temp.EndNodeID) != null)
  459.                     {
  460.                         tempPoint = GetPoint(temp.EndNodeID);
  461.                         tempPoint.Hn = temp.Weight;
  462.                         tempArraylist.Add(tempPoint);
  463.                     }
  464.                     else
  465.                     {
  466.                         continue;
  467.                     }
  468.                 }
  469.                 return tempArraylist;
  470.             }
  471.             public void ResetPointState()//将程序恢复到初始状态
  472.             {
  473.             }
  474.         }
  475.         
  476.         #endregion
  477.         #region NetShortPathAnalyse
  478.         //对接口的实现
  479.         public class BLL_NetShortPathAnalyse : iNetShortPathAnalyse//对接口 iNetShortPathAnalyse的实现
  480.         {
  481.             private NETA_NET TheAnalyseNET;
  482.             
  483.             private NETA_BinaryHeap NetShortPathAnalyseBinaryHeap = NETA_BinaryHeap.NETA_BinaryHeapInstance;
  484.             public BLL_NetShortPathAnalyse()
  485.             {
  486.                 TheAnalyseNET = new NETA_NET();
  487.             }
  488.             
  489.             #region iNetShortPathAnalyse 成员            
  490.             public NETA_Point NetShortPathAnalyse(string StartID, string EndID)
  491.             {
  492.                 try
  493.                 {
  494.                     if (TheAnalyseNET.pArraylistRoad == null)
  495.                     {
  496.                         MessageBox.Show("请先初始化网络");
  497.                         return null;
  498.                     }
  499.                   
  500.                     NETA_Point StartPt = TheAnalyseNET.GetPoint(StartID);
  501.                     NETA_Point EndPt = TheAnalyseNET.GetPoint(EndID);
  502.                     if (StartPt == null)
  503.                     {
  504.                         MessageBox.Show("起点在网络中不存在,请重新选择!");
  505.                         return null;
  506.                     }
  507.                     if (EndPt == null)
  508.                     {
  509.                         MessageBox.Show("终点在网络中不存在,请重新选择!");
  510.                         return null;
  511.                     }
  512.                     if (StartPt.IsEnabled == false || EndPt.IsEnabled == false)
  513.                     {
  514.                         MessageBox.Show("起点或终点被设置为障碍点,请重新选择!");
  515.                         return null;
  516.                     }
  517.                     //开始处理。
  518.                     TheAnalyseNET.ResetPointState();
  519.                     NetShortPathAnalyseBinaryHeap.Clear();
  520.                     StartPt.Fn = 0;
  521.                     StartPt.Gn = 0;
  522.                     StartPt.AnalyseState = PointAnalyseState.InOpenList;
  523.                     BinaryHeapItem MyItem = new BinaryHeapItem();
  524.                     MyItem.Fn = StartPt.Fn;
  525.                     MyItem.KeyID = StartPt.PointID;
  526.                     NetShortPathAnalyseBinaryHeap.AddItem(MyItem);
  527.                     NETA_Point CurrPt;
  528.                     BinaryHeapItem CurrItem;
  529.                     while (NetShortPathAnalyseBinaryHeap.ItemCount > 0)//openList为空程序结束
  530.                     {
  531.                         CurrItem = NetShortPathAnalyseBinaryHeap.GetAndRemoveMinFnItem();
  532.                         //获取当前点。
  533.                         CurrPt = TheAnalyseNET.GetPoint(CurrItem.KeyID);
  534.                         if (CurrPt.PointID == EndPt.PointID) return CurrPt;//找到了终点,程序结束
  535.                         CurrPt.AnalyseState = PointAnalyseState.InCloseList;
  536.                         System.Collections.ArrayList ChildrenPt = TheAnalyseNET.GetChildrenPoints(CurrPt);
  537.                         foreach (NETA_Point ChildPt in ChildrenPt)
  538.                         {
  539.                             if (ChildPt.IsEnabled == false || ChildPt.AnalyseState == PointAnalyseState.InCloseList)
  540.                             { }
  541.                             else if (ChildPt.AnalyseState != PointAnalyseState.InOpenList)
  542.                             {
  543.                                 ChildPt.AnalyseState = PointAnalyseState.InOpenList;
  544.                                 ChildPt.ParentPoint = CurrPt;
  545.                                // MessageBox.Show(ChildPt.PointID+"/n"+ChildPt.Hn.ToString());
  546.                                 ChildPt.Gn = CurrPt.Gn + ChildPt.Hn;//Hn起临时储存本次Weight作用
  547.                                 ChildPt.Hn = ComputeTheHnValue(ChildPt, EndPt);
  548.                                 ChildPt.Fn = ChildPt.Gn + ChildPt.Hn;
  549.                                 CurrItem = new BinaryHeapItem();
  550.                                 CurrItem.KeyID = ChildPt.PointID;
  551.                                 CurrItem.Fn = ChildPt.Fn;
  552.                                 NetShortPathAnalyseBinaryHeap.AddItem(CurrItem);
  553.                             }
  554.                             else if (ChildPt.AnalyseState == PointAnalyseState.InOpenList)
  555.                             {
  556.                                 if (CurrPt.Gn + ChildPt.Hn < ChildPt.Gn)
  557.                                 {
  558.                                     ChildPt.ParentPoint = CurrPt;
  559.                                     ChildPt.Gn = CurrPt.Gn + ChildPt.Hn;
  560.                                     ChildPt.Hn = ComputeTheHnValue(ChildPt, EndPt);
  561.                                     ChildPt.Fn = ChildPt.Gn + ChildPt.Hn;
  562.                                     NetShortPathAnalyseBinaryHeap.MinishItemFnValue(ChildPt.PointID, ChildPt.Fn);
  563.                                 }
  564.                             }
  565.                         }
  566.                     }
  567.                     //if (NetShortPathAnalyseBinaryHeap.ItemCount == 0)
  568.                     MessageBox.Show("未找到连通路径!");
  569.                     return null;
  570.                 }
  571.                 catch (Exception e)
  572.                 {
  573.                     MessageBox.Show("BLL_NetShortPathAnalyse.NetShortPathAnalyse错误" + e.Message);
  574.                     return null;
  575.                 }
  576.             }
  577.            
  578.             public ArrayList resultPointLine(string start, string end)//获取路径点ID
  579.             {
  580.                 ArrayList temparr = new ArrayList();
  581.                 
  582.                 NETA_Point tempnode = TheAnalyseNET.GetPoint(end);
  583.                 while (start != tempnode.PointID)
  584.                 {
  585.                     if (tempnode.ParentPoint != null)
  586.                     {
  587.                         foreach (Edge temEdge in tempnode.ParentPoint.EdgeList)
  588.                         {
  589.                             if (temEdge.EndNodeID == tempnode.PointID)
  590.                             {
  591.                                 temparr.Add(temEdge.EdgeFID);
  592.                             }
  593.                         }
  594.                         tempnode = tempnode.ParentPoint;
  595.                     }
  596.                     else
  597.                     {
  598.                         return null;
  599.                     }
  600.                     
  601.                 }
  602.                           
  603.                return temparr;
  604.             }
  605.             public double ComputeTheHnValue(NETA_Point currPt, NETA_Point EndPt)
  606.             {
  607.                 try
  608.                 {
  609.                     return doCompute(currPt, EndPt);
  610.                 }
  611.                 catch (Exception e)
  612.                 {
  613.                     MessageBox.Show("计算因子错误," + e.Message);
  614.                     return 0;
  615.                 }
  616.             }
  617.             public double doCompute(NETA_Point currPt, NETA_Point EndPt)
  618.             {
  619.                 double radLat1 = Rad(currPt.X);
  620.                 double radLat2 = Rad(EndPt.X);
  621.                 double a = radLat1 - radLat2;
  622.                 double b = Rad(currPt.Y) - Rad(EndPt.Y);
  623.                 double s = 2 * Math.Asin(Math.Sqrt(Math.Pow(Math.Sin(a / 2), 2) + Math.Cos(radLat1) * Math.Cos(radLat2) * Math.Pow(Math.Sin(b / 2), 2)));
  624.                 s = s * 6378137.0;  //(gs == GaussSphere.WGS84 ? 6378137.0 : (gs == GaussSphere.Xian80 ? 6378140.0 : 6378245.0));
  625.                 s = Math.Round(s * 10000) / 10000;
  626.                 return s;
  627.             }
  628.             public static double Rad(double d)
  629.             {
  630.                 return d * Math.PI / 180.0;
  631.             }
  632.             //GaussSphere 为自定义枚举类型
  633.             /// <summary>
  634.             /// 高斯投影中所选用的参考椭球
  635.             /// </summary>
  636.             public enum GaussSphere
  637.             {
  638.                 Beijing54,
  639.                 Xian80,
  640.                 WGS84,
  641.             }
  642.             #endregion
  643.         }
  644.         #endregion
  645.         #endregion
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值