資源簡(jiǎn)介
描述:
在矢量多邊形區(qū)域中,一個(gè)坐標(biāo)點(diǎn)的位置是否在區(qū)域內(nèi)
算法:
C#代碼,適用于任意多邊形(凹凸多邊形),但是沒有考慮實(shí)際誤差范圍的情況(應(yīng)用在實(shí)際問題解決中,接近區(qū)域一定范圍是可以忽略的,這個(gè)誤差范圍考慮后算法的復(fù)雜度會(huì)加倍,所以沒有做這方面的考慮)

代碼片段和文件信息
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();
????????}
????????///?
????????///??判斷指定的經(jīng)緯度坐標(biāo)點(diǎn)是否落在指定的多邊形區(qū)域內(nèi)
????????///?
????????///?指定點(diǎn)的經(jīng)度
????????///?指定點(diǎn)的緯度
????????///?指定多邊形區(qū)域各個(gè)節(jié)點(diǎn)坐標(biāo)
????????///?True?落在范圍內(nèi)?False?不在范圍內(nèi)
????????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;
????????}
????}
????///?
????///?坐標(biāo)
????///?
????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;?}
????????????
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件????????3164??2012-06-16?14:56??Program.cs
評(píng)論
共有 條評(píng)論