sample.py 文件源码

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

项目:groundfailure 作者: usgs 项目源码 文件源码
def getClassBalance(pshapes, bounds, proj):
    """
    Get native class balance of projected shapes, assuming a rectangular
    bounding box.

    Args:
        pshapes: Sequence of projected shapely shapes.
        bounds: Desired bounding box, in decimal degrees.
        proj: PyProj object defining orthographic projection of shapes.

    Returns:
        Float fraction of hazard polygons (area of hazard polygons/total
        area of bbox).
    """

    xmin, ymin, xmax, ymax = bounds
    bpoly = Polygon([(xmin, ymax),
                     (xmax, ymax),
                     (xmax, ymin),
                     (xmin, ymin)])
    project = partial(
        pyproj.transform,
        pyproj.Proj(proj='latlong', datum='WGS84'),
        proj)
    bpolyproj = transform(project, bpoly)
    totalarea = bpolyproj.area
    polyarea = 0
    for pshape in pshapes:
        polyarea += pshape.area

    return polyarea / totalarea
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号