如何从 {'northeast': {'lat':}, 'southwest': {'lat': }} (google maps) Python 创建多边形

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

Google 将 returns 位置边界映射为具有 'northeast' 和 'southwest' 点的正方形。

如何根据这些数据计算多边形?

谢谢!

假设你有这样的字典:

bounds = {'northeast': {'lat': 10, 'lng': 15}, 'southwest': {'lat': 5, 'lng': 6}}

然后你可以使用shapely.geometry.box函数,它以"minx, miny, maxx, maxy"为参数:

from shapely.geometry import box

bounds_polygon = box(bounds['southwest']['lng'], bounds['southwest']['lat'],
                     bounds['northeast']['lng'], bounds['northeast']['lat'])

给出:

>>> print(bounds_polygon)
POLYGON ((15 5, 15 10, 6 10, 6 5, 15 5))