i need to check if longitude, latitude is in polygon in python3
the code below works but i have problem putting data from variable
lng_lat = Point(42.01410106690003, 20.97770690917969)
#this is how i need to add data
polygon = Polygon([(0, 0), (0, 1), (1, 1), (1, 0)])
print(lng_lat.within(poly))
but my data are like this (i get data from json file with json.load)
coordinate[0]=[[20.94320297241211, 41.99777372492389], [20.923118591308594, 41.98578066472604] , [20.917625427246094, 41.970467091533], [20.936164855957028, 41.94825586972943]]
so how can i pass data from coordinates[0] to polygon wich requires ( ) instenad of [ ]
and this dont work
polygon = Polygon(coordinates[0])
>Solution :
It isn’t clear whether they need to be tuples or Point instances…
Also your print statement is trying to print poly which doesn’t exist in the code you included.
lng_lat = Point(42.01410106690003, 20.97770690917969)
coordinate[0]=[[20.94320297241211, 41.99777372492389], [20.923118591308594, 41.98578066472604] , [20.917625427246094, 41.970467091533], [20.936164855957028, 41.94825586972943]]
If tuples then:
data = [tuple(i) for i in coorinate[0]]
polygon = Polygon(data)
print(lng_lat.within(polygon))
and if they need to be Point Instances:
data = [Point(i) for i in coorinate[0]]
polygon = Polygon(data)
print(lng_lat.within(polygon))