Dmitriy Grankin
Dmitriy Grankin

Reputation: 608

How to create Polygon out of {'northeast': {'lat':}, 'southwest': {'lat': }} (google maps) Python

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

Answers (1)

joris
joris

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

Related Questions