Turn from: http://www.cnblogs.com/gis_gps/archive/2009/02/12/1389071.html
Spare
I. Background:
How to determine whether a specified latitude and longitude point falls in a polygon region.
Second, the Implementation Code (Delphi)
Type
Tmypoint = Packed record
x:double;
y:double;
End
{*------------------------------------------------------------------------------
Determines whether the specified latitude and longitude coordinate point falls within the specified polygon region
@param the longitude of the ALon point
@param the latitude of the Alat point
@param apoints Specifies the coordinates of each node of the polygon region
@return True falls within range False is not in range
------------------------------------------------------------------------------*}
function Isptinpoly (ALon, alat:double; Apoints:array of Tmypoint): Boolean;
Var
Isum, icount, Iindex:integer;
DLon1, DLon2, DLAT1, DLAT2, dlon:double;
Begin
Result: = False;
if (Length (apoints) < 3) Then
Begin
Result: = False;
Exit;
End
Isum: = 0;
Icount: = Length (apoints);
For Iindex: =0 to ICount-1 do
Begin
if (Iindex = iCount-1) Then
Begin
DLon1: = Apoints[iindex]. X
DLAT1: = Apoints[iindex]. Y
DLon2: = Apoints[0]. X
DLAT2: = Apoints[0]. Y
End
Else
Begin
DLon1: = Apoints[iindex]. X
DLAT1: = Apoints[iindex]. Y
DLon2: = Apoints[iindex + 1]. X
DLAT2: = Apoints[iindex + 1]. Y
End
if ((Alat >= dLat1) and (Alat < DLAT2)) or ((ALAT>=DLAT2) and (Alat < DLAT1)) then
Begin
if (ABS (DLAT1-DLAT2) > 0) Then
Begin
Dlon: = DLon1-((dlon1-dlon2) * (Dlat1-alat))/(DLAT1-DLAT2);
if (Dlon < ALon) Then
INC (isum);
End
End
End
if (isum mod 2 <> 0) Then
Result: = True;
End
_______________________________________________________________________________________________________________ _____________
C # algorithm:///<summary> /// Determines whether the specified latitude and longitude coordinate points fall within the specified polygon area ///</summary> ///<param name= " ALon "> Point of Longitude </param> ///<param name=" Alat "> Point of Latitude </ param> ///<param name= "apoints" > Specify Polygon area node coordinates </param> ///<returns>true fall within range False not in range </returns> public bool Isptinpoly (double ALon, double Alat, point[] apoints) { int isum, icount, Iindex; double DLon1, DLon2, DLAT1, DLAT2, Dlon; if (apoints.length< 3) { return false; } isum = 0; icount = apoints.length; for (iindex = 0; iindex < iCount-1 iindex++) &NB sp; { 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 >= dLat2) && (Alat < DLAT1)) { if (Math.Abs ( DLAT1-DLAT2) > 0) {