shapes.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:cyphon 作者: dunbarcyber 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号