I'm trying to combine pairs of numbers passed in via sys.argv
.
Example:
python myscript.py -35.12323 112.76767 -36.33345 112.76890 -33.68689 111.8980
My goal would be to turn these into sets of two's in tuples. Like such:
((-35.12323,112.76767),(-36.33345,112.76890),(-33.68689,111.8980))
This is what I've tried to so far, but it has a problem when I pass the results to the Shapely Point and Polygon methods.
from shapely.geometry import Polygon
from shapely.geometry import Point
import sys
def args_to_tuple(list):
arglist = []
for coord in list:
arglist.append(float(coord))
i = 0
polylist = []
for xory in arglist:
tmp = (arglist[i],arglist[i+1])
polylist.append(tmp)
return tuple(polylist)
poly = Polygon(args_to_tuple(sys.argv[3:]))
# xy pair for point is first two sys args
point = Point(args_to_tuple(sys.argv[1:3]))
print point.within(poly) # should result in true, but doesn't
print poly.contains(point) # should result in true, but doesn't
It seems like this would be something common in itertools, but I can't seem to find anything in that module that lets you grab items in a pair.