最寄りの国立公園名を見つける
まずは、単一の採掘サイトに対するカスタムクエリから始めましょう。ここでは、特定の採掘サイトに最も近い国立公園の名前を特定します。
採掘サイト(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)