Skip to content

Commit b222ade

Browse files
committed
check if a lat-lon cooridinate lies inside a polygon
1 parent 6385286 commit b222ade

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

pointInPolygon.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python
2+
3+
polyCorners = 4
4+
poly_1_x = [22.017965, 22.017852, 22.016992, 22.017187]
5+
poly_1_y = [85.432761, 85.433074, 85.432577, 85.432243]
6+
7+
poly_2_x = [22.017187, 22.016992, 22.015849, 22.015982]
8+
poly_2_y = [85.432243, 85.432577, 85.431865, 85.431574]
9+
10+
poly_3_x = [22.015850, 22.015636, 22.015874, 22.016053]
11+
poly_3_y = [85.431406, 85.43173, 85.431889, 85.431516]
12+
13+
def main():
14+
point_M = (22.017603, 85.432641)
15+
point_L = (22.016598, 85.432157)
16+
point_O = (22.015838, 85.431621)
17+
print("Does the point{} lie in the polygon? {}".format(str(point_O), pointInPolygon(point_O, poly_3_x, poly_3_y)))
18+
19+
def pointInPolygon(point, polyX, polyY):
20+
i = 0
21+
j = polyCorners-1
22+
x = point[0]
23+
y = point[1]
24+
oddNodes = False
25+
print(polyX)
26+
print(polyY)
27+
for i in range(0, polyCorners):
28+
if((polyY[i]<y and polyY[j]>=y) or (polyY[j]<y and polyY[i]>=y)):
29+
if (polyX[i]+(y-polyY[i])/(polyY[j]-polyY[i])*(polyX[j]-polyX[i])<x):
30+
oddNodes = not oddNodes
31+
j=i
32+
33+
return oddNodes
34+
35+
if __name__=="__main__":
36+
main()

0 commit comments

Comments
 (0)