- Code: Select all
30.72,-97.27 30.86,-97.6 30.98,-97.56 31.01,-97.46 30.98,-97.07 30.89,-96.9 30.66,-96.76 30.46,-97.16 30.72,-97.27
- Code: Select all
[(35.44,-90.28),(35.65,-90.29),(35.82,-89.89),(35.4,-90),(35.31,-90.4),(35.44,-90.28)]
The code fails with "Script Error embedded script: need more than 1 value to unpack" If I replace the line: polygon = noaaAlertCapPolygon with the formatted list above, it works. I assume there's a way to parse the variable back into Python. What am I missing?
- Code: Select all
# Determine if a point is inside a given polygon or not
# Polygon is a list of (x,y) pairs. This function
# returns True or False. The algorithm is called
# the "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:
xints = (y-p1y)*(p2x-p1x)/(p2y-p1y)+p1x
if p1x == p2x or x <= xints:
inside = not inside
p1x,p1y = p2x,p2y
return inside
## Test
noaaAlertCapPolygon = list(indigo.variables[1823083030].value) # "noaaAlert1CapPolygon"
lat = float(indigo.variables[201899193].value) # "homeLatitude"
lon = float(indigo.variables[1966208654].value) # "homeLongitude"
polygon = noaaAlertCapPolygon
point_x = lat
point_y = lon
## Call the function with the points and the polygon
polygonInside = point_in_poly(point_x,point_y, polygon)
# indigo.variable.updateValue(104702043, value=str(polygonInside)) # "noaaAlertPolygonInside1"
indigo.server.log("Polygon Inside: " + str(polygonInside))