找出最近的國家公園名稱
先從單一採礦據點的自訂查詢開始。這裡要判定距離該採礦據點最近的國家公園名稱。
採礦據點(mining_sites)與國家公園(national_parks)這兩個資料集都已經載入。
本練習屬於課程
在 Python 中處理地理空間資料
練習說明
- 取出
geometry的第一個元素,指定給變數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)