Reputation: 608
Google Maps returns location bounds as a square with 'northeast' and 'southwest' points.
How to calculate a Polygon out of this data?
thank you!
Upvotes: 0
Views: 1037
Reputation: 139172
Assuming you have a dictionary like this:
bounds = {'northeast': {'lat': 10, 'lng': 15}, 'southwest': {'lat': 5, 'lng': 6}}
then you can use the shapely.geometry.box
function, which takes "minx, miny, maxx, maxy" as arguments:
from shapely.geometry import box
bounds_polygon = box(bounds['southwest']['lng'], bounds['southwest']['lat'],
bounds['northeast']['lng'], bounds['northeast']['lat'])
which gives:
>>> print(bounds_polygon)
POLYGON ((15 5, 15 10, 6 10, 6 5, 15 5))
Upvotes: 4