[Original] determines whether a point falls into a polygon.

Source: Internet
Author: User

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;

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.