資源簡介
描述:
在矢量多邊形區域中,一個坐標點的位置是否在區域內
算法:
C#代碼,適用于任意多邊形(凹凸多邊形),但是沒有考慮實際誤差范圍的情況(應用在實際問題解決中,接近區域一定范圍是可以忽略的,這個誤差范圍考慮后算法的復雜度會加倍,所以沒有做這方面的考慮)

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;
namespace?p
{
????class?Program
????{
????????static?void?Main(string[]?args)
????????{
????????????Point?p?=?new?Point(112.3839540000?37.9901770000);
????????????Point[]?ps?=?new?Point[]?{?new?Point(112.4091887500?38.0200324167)?new?Point(112.4668669727?37.7316897817)?new?Point(112.6701140430?37.7686085000)?new?Point(112.6234221484?38.0070487978)?};
????????????Console.WriteLine(“x:“?+?p.X?+?“y:“?+?p.Y);
????????????Console.WriteLine(“result:“?+?(isPtInPoly(p.X?p.Y?ps)???“yes“?:?“no“));
????????????Console.ReadKey();
????????}
????????///?
????????///??判斷指定的經緯度坐標點是否落在指定的多邊形區域內
????????///?
????????///?指定點的經度
????????///?指定點的緯度
????????///?指定多邊形區域各個節點坐標
????????///?True?落在范圍內?False?不在范圍內
????????public?static?bool?isPtInPoly(double?ALon?double?ALat?Point[]?APoints)
????????{
????????????int?iSum?iCount?iIndex;
????????????double?dLon1?=?0?dLon2?=?0?dLat1?=?0?dLat2?=?0?dLon;
????????????if?(APoints.Length?3)
????????????{
????????????????return?false;
????????????}
????????????iSum?=?0;
????????????iCount?=?APoints.Length;
????????????for?(iIndex?=?0;?iIndex?????????????{
????????????????if?(iIndex?==?iCount?-?1)
????????????????{
????????????????????dLon1?=?APoints[iIndex].X;
????????????????????dLat1?=?APoints[iIndex].Y;
????????????????????dLon2?=?APoints[0].X;
????????????????????dLat2?=?APoints[0].Y;
????????????????}
????????????????else
????????????????{
????????????????????dLon1?=?APoints[iIndex].X;
????????????????????dLat1?=?APoints[iIndex].Y;
????????????????????dLon2?=?APoints[iIndex?+?1].X;
????????????????????dLat2?=?APoints[iIndex?+?1].Y;
????????????????}
????????????????if?(((ALat?>=?dLat1)?&&?(ALat?=?dLat2)?&&?(ALat?????????????????{
????????????????????if?(Math.Abs(dLat1?-?dLat2)?>?0)
????????????????????{
????????????????????????dLon?=?dLon1?-?((dLon1?-?dLon2)?*?(dLat1?-?ALat))?/?(dLat1?-?dLat2);
????????????????????????if?(dLon?????????????????????????????iSum++;
????????????????????}
????????????????}
????????????}
????????????if?((iSum?%?2)?!=?0)
????????????????return?true;
????????????return?false;
????????}
????}
????///?
????///?坐標
????///?
????public?class?Point
????{
????????private?Double?x;
????????private?Double?y;
????????public?Point()
????????{
????????????this.x?=?0;
????????????this.y?=?0;
????????}
????????public?Point(double?_x?double?_y)
????????{
????????????this.x?=?_x;
????????????this.y?=?_y;
????????}
????????public?Double?X
????????{
????????????get?{?return?x;?}
????????????set?{?x?=?value;?}
????????}
????????public?Double?Y
????????{
????????????get?{?return?y;?}
????????????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????3164??2012-06-16?14:56??Program.cs
- 上一篇:C# mapx 開發GIS
- 下一篇:電力組態設計軟件.net wpf源碼
評論
共有 條評論