Reputation: 1010
I have a list of coordinates like so:
[
-79.763635,
42.257327
],
[
-73.343723,
45.046138
],
[
-74.006183,
40.704002
],
[
-79.763635,
42.257327
]
I want to see if a point SomeLat, SomeLong is inside these predefined borders.
I trie used shapely.geometry
but the json has to be configured a certain way for it to create a shape
(I cannot change that json).
What would be the best way to tell if a point I provide is inside those defined borders
Upvotes: 0
Views: 910
Reputation: 347
I am not sure if this the best way, but this is how I would go about it. I would identify all the points making up the borders of the polygon, which is obtainable from the data you have. Then I would pull together every two border extreme latitude coordinates that share the same longitude coordinate. The final set should be a list of longitude coordinates and their corresponding latitude ranges, which you could loop through to decide if a point is in the polygon.
Upvotes: 0
Reputation: 18106
You can pass a list of lists/tuples to shapely:
>>> from shapely.geometry import Point, Polygon
>>> bbox = [ (0, 0), (0,2), (2,2), (2,0)]
>>> poly = Polygon(bbox)
>>> point = Point(1, 1)
>>> poly.contains(point)
True
Upvotes: 3