查找最近国家公园的名称
先针对单个矿点执行一次自定义查询。这里,您将确定距离该矿点最近的国家公园名称。
矿点数据集(mining_sites)和国家公园数据集(national_parks)已加载。
本练习是课程的一部分
在 Python 中处理地理空间数据
练习说明
- 选取几何的第 1 个元素,并将其赋给名为
single_mine的变量。 - 计算每个国家公园到
single_mine的距离。将结果命名为dist。 - 使用
idxmin()方法获取dist的最小值索引。 - 使用获得的索引配合
.loc[]属性获取最近国家公园的名称,并打印结果。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Get the geometry of the first row
single_mine = mining_sites.____[____]
# Calculate the distance from each national park to this mine
dist = ____
# The index of the minimal distance
idx = dist.____
# Access the name of the corresponding national park
closest_park = national_parks.____[____, '____']
print(closest_park)