def convert_circle_to_rectangle(point, radius_m):
"""
(tuple(int or float, int or float), int or float) -> GEOSGeometry Polygon
Takes a circle as a (lng, lat) tuple and a radius in meters. Returns the
smallest rectangular Polygon that encompasses the circle.
"""
# reverse the lng, lat order to convert to geopy Point format
center = reverse_coordinate_order(point)
# create a geopy coordinate calculator for the given distance
calculator = vincenty(meters=radius_m)
# calculate points at the given distance in the cardinal directions
n_pt = calculator.destination(point=center, bearing=0)
s_pt = calculator.destination(point=center, bearing=180)
e_pt = calculator.destination(point=center, bearing=90)
w_pt = calculator.destination(point=center, bearing=270)
bounds = Bounds(n_lat=n_pt.latitude, s_lat=s_pt.latitude,
e_lng=e_pt.longitude, w_lng=w_pt.longitude)
return bounds.bounding_box
评论列表
文章目录