#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 #交点个数