문제 설명
{'northeast': {'lat':}, 'southwest': {'lat': }}(Google 지도) Python에서 다각형을 만드는 방법 (How to create Polygon out of {'northeast': {'lat':}, 'southwest': {'lat': }} (google maps) Python)
Google 지도는 위치 경계를 '북동쪽' 및 '남서쪽' 지점이 있는 정사각형으로 반환합니다.
이 데이터에서 다각형을 계산하는 방법은 무엇입니까?
감사합니다!</ 피>
참조 솔루션
방법 1:
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))
(by Dmitriy Grankin、joris)