投影一個點
在前一章中,我們處理了艾菲爾鐵塔的位置。我們同樣提供了投影座標系統中的座標,方便你進行距離等計算。現在回到這個經典地標,將它的位置用地理座標表示:48°51′29.6″N,2°17′40.2″E。或以小數表示:緯度 48.8584、經度 2.2945。
Shapely 的幾何物件本身沒有 CRS 的概念,因此無法直接轉換到其他 CRS。我們將使用 GeoPandas,把艾菲爾鐵塔的點位置轉換到另一個 CRS。做法是把這個單一點放進 GeoSeries,使用 to_crs() 方法,然後再取出該點。
GeoPandas 已經匯入。
本練習屬於課程
在 Python 中處理地理空間資料
練習說明
- 使用艾菲爾鐵塔的座標建立一個 shapely 的點物件,指派給變數
eiffel_tower。 - 建立一個 GeoSeries(命名為
s_eiffel_tower),其唯一元素為艾菲爾鐵塔,並將 CRS 指定為 EPSG:4326。 - 將
s_eiffel_tower轉換為 EPSG:2154,並將結果命名為s_eiffel_tower_projected
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Construct a Point object for the Eiffel Tower
from shapely.geometry import Point
eiffel_tower = ____
# Put the point in a GeoSeries with the correct CRS
s_eiffel_tower = geopandas.GeoSeries([____], crs={'init': '____'})
# Convert to other CRS
s_eiffel_tower_projected = s_eiffel_tower.____
# Print the projected point
print(s_eiffel_tower_projected)