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)
评论列表
文章目录