python 判断点是否在多边形里,python之 判断点是否在多边形范围内

#coding=UTF-8

importcsvimportjson#点是否在外包矩形内

def isPoiWithinBox(poi, sbox, toler=0.0001):#sbox=[[x1,y1],[x2,y2]]

#不考虑在边界上,需要考虑就加等号

if poi[0] > sbox[0][0] and poi[0] < sbox[1][0] and poi[1] > sbox[0][1] and poi[1] < sbox[1][1]:returnTrueif toler >0:pass

returnFalse#射线与边是否有交点

def isRayIntersectsSegment(poi, s_poi, e_poi): #[x,y] [lng,lat]

if s_poi[1] == e_poi[1]: #排除与射线平行、重合,线段首尾端点重合的情况

returnFalseif s_poi[1] > poi[1] and e_poi[1] > poi[1]:returnFalseif s_poi[1] < poi[1] and e_poi[1] < poi[1]:returnFalseif s_poi[1] == poi[1] and e_poi[1] > poi[1]:returnFalseif e_poi[1] == poi[1] and s_poi[1] > poi[1]:returnFalseif s_poi[0] < poi[0] and e_poi[1] < poi[1]:returnFalse

xseg= e_poi[0] - (e_poi[0] - s_poi[0]) * (e_poi[1] - poi[1]) / (e_poi[1] - s_poi[1]) #求交

if xseg

def isPoiWithinSimplePoly(poi, simPoly, tolerance=0.0001):#点;多边形数组;容限

#simPoly=[[x1,y1],[x2,y2],……,[xn,yn],[x1,y1]]

#如果simPoly=[[x1,y1],[x2,y2],……,[xn,yn]] i循环到终点后还需要判断[xn,yx]和[x1,y1]

#先判断点是否在外包矩形内

if not isPoiWithinBox(poi, [[0, 0], [180, 90]], tolerance):returnFalse

polylen=len(simPoly)

sinsc= 0 #交点个数

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值