1 Star 0 Fork 0

cq383768026/Learn

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
pointinpoly.py 840 Bytes
一键复制 编辑 原始数据 按行查看 历史
geospatialpython 提交于 2015-06-19 01:37 +08:00 . Consolidated repositories
# 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)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/cq383768026/Learn.git
[email protected]:cq383768026/Learn.git
cq383768026
Learn
Learn
master

搜索帮助