I. background:
How can I determine whether a specified latitude and longitude point falls into a polygon area?
II. ImplementationCode(Delphi)
Code
Type
Tmypoint = Packed Record
X: Double;
Y: Double;
End ;
{ *------------------------------------------------------------------------------
Determines whether the specified coordinate point of longitude and latitude falls within the specified polygon area.
@ Param eon the longitude of the specified Vertex
@ Param Alat: Specify the latitude of a vertex.
@ Param apoints specify coordinates of each node in the Polygon Area
@ Return true falls into the range. False is not in the range.
------------------------------------------------------------------------------* }
Function Isptinpoly (Eon, 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 < On) Then
INC (isum );
End ;
End ;
End;
If(IsumMoD 2 <> 0)Then
Result:=True;
End;