投影為 Web Mercator 以使用網頁磚圖
在第 1 章中,你做過一個練習:用 contextily 套件繪製巴黎餐廳的位置並加入背景地圖。
目前,contextily 假設你的資料使用 Web Mercator 投影,這是多數網頁磚圖服務所採用的座標系統。在那個練習中,我們已提供了對應的 CRS,因此你不需要特別處理這一點。
然而,實務上你的資料通常不會是 Web Mercator(EPSG:3857),你需要自行將它們與網頁磚圖對齊。
GeoPandas、matplotlib 和 contextily 已經匯入。
本練習屬於課程
在 Python 中處理地理空間資料
練習說明
- 將
restaurants資料集轉換為 Web Mercator 投影(EPSG:3857)。將結果命名為restaurants_webmercator。 - 繪製此投影後的資料集(將標記大小設為 1),並使用
contextily加入背景地圖。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Convert to the Web Mercator projection
restaurants_webmercator = restaurants.____
# Plot the restaurants with a background map
ax = ____
contextily.____
plt.show()