Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

python: convert parenthesis to bracket

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)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading