sample.py 文件源码

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

项目:groundfailure 作者: usgs 项目源码 文件源码
def sampleShapes(shapes, xypoints, attribute):
    """
    Get the attribute value at each of the input XY points for sequence of
    input shapes (decimal degrees). Slower than sampling grids.

    Args:
        shapes: Sequence of shapes (decimal degrees) of predictor variable.
        xypoints: 2D numpy array of XY points, in decimal degrees.
        attribute: String name of attribute to sample in each of the shapes.

    Returns:
        1D array of attribute values at each of XY points.
    """
    samples = []
    for x, y in xypoints:
        for tshape in shapes:
            polygon = shape(tshape['geometry'])
            point = Point(x, y)
            if polygon.contains(point):
                sample = tshape['properties'][attribute]
                samples.append(sample)
    return np.array(samples)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号