如何使用{'northeast':{'lat':},'southwest':{'lat':}}(谷歌地图)Python

时间:2019-01-08 14:54:08

标签: python geometry shapely geopandas

Google Maps返回具有“东北”和“西南”点的正方形的位置范围。

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

谢谢!

1 个答案:

答案 0 :(得分:2)

假设您有这样的字典:

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))