在投影座標系中計算距離
現在我們已經把艾菲爾鐵塔的位置轉成投影座標系,就可以計算到其他點的距離。
上一個練習產生的 s_eiffel_tower_projected(包含投影後的 Point)已經提供,並且我們把單一點取出存到變數 eiffel_tower。另外,使用 WGS84 座標的 restaurants 資料框也已載入。
本練習屬於課程
在 Python 中處理地理空間資料
練習說明
- 將
restaurants轉換成與艾菲爾鐵塔點相同的 CRS。本練習不要指定epsg參數,改用.crs屬性。 - 計算所有餐廳到艾菲爾鐵塔的距離。
- 印出最小的距離。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Extract the single Point
eiffel_tower = s_eiffel_tower_projected[0]
# Ensure the restaurants use the same CRS
restaurants = restaurants.____
# The distance from each restaurant to the Eiffel Tower
dist_eiffel = ____
# The distance to the closest restaurant
print(____)