从栅格图层提取信息
现在,基于一个矢量文件从栅格图层中提取信息。该功能由 rasterstats 包提供。针对本练习,我们将通过获取每个采矿点位置最近的栅格像元值,来确定所有采矿点的植被类型。
采矿点数据集的一个子集(mining_sites)已加载,GeoPandas 和 matplotlib 已导入。
本练习是课程的一部分
在 Python 中处理地理空间数据
练习说明
- 导入
rasterstats包。 - 使用
rasterstats.point_query()为采矿点位置(mining_sites)提取最近的栅格值,并将结果赋给新列'vegetation'。 - 使用
'vegetation'列为点着色,绘制采矿点数据的图。请确保添加图例。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Import the rasterstats package
____
# Extract the nearest value in the raster for all mining sites
vegetation_raster = "central_africa_vegetation_map_foraf.tif"
mining_sites['vegetation'] = ____(____, ____, interpolate='nearest')
print(mining_sites.head())
# Replace numeric vegation types codes with description
mining_sites['vegetation'] = mining_sites['vegetation'].replace(vegetation_types)
# Make a plot indicating the vegetation type
____
plt.show()