FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
geospatialpython/pointinpoly.py at master · GeospatialPython/geospatialpython · GitHub
GeospatialPython
/
geospatialpython
Public
Notifications
You must be signed in to change notification settings
Fork
8
Star
14
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
geospatialpython
/
pointinpoly.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
34 lines (25 loc) · 873 Bytes
Breadcrumbs
geospatialpython
/
pointinpoly.py
Copy path
File metadata and controls
34 lines (25 loc) · 873 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Determine if a point is inside a given polygon or not
# Polygon is a list of (x,y) pairs. This fuction
# returns True or False. The algorithm is called
# "Ray Casting Method".
def
point_in_poly
(
x
,
y
,
poly
):
n
=
len
(
poly
)
inside
=
False
p1x
,
p1y
=
poly
[
0
]
for
i
in
range
(
n
+
1
):
p2x
,
p2y
=
poly
[
i
%
n
]
if
y
>
min
(
p1y
,
p2y
):
if
y
<=
max
(
p1y
,
p2y
):
if
x
<=
max
(
p1x
,
p2x
):
if
p1y
!=
p2y
:
xinters
=
(
y
-
p1y
)
*
(
p2x
-
p1x
)
/
(
p2y
-
p1y
)
+
p1x
if
p1x
==
p2x
or
x
<=
xinters
:
inside
=
not
inside
p1x
,
p1y
=
p2x
,
p2y
return
inside
## Test
polygon
=
[(
0
,
10
),(
10
,
10
),(
10
,
0
),(
0
,
0
)]
point_x
=
5
point_y
=
5
## Call the fuction with the points and the polygon
print
point_in_poly
(
point_x
,
point_y
,
polygon
)
Back
|
FazBrowse Home
|
New Git URL