探索 Land Use 資料集
在接下來的練習中,我們會先介紹一個新資料集:巴黎的土地使用資料集(基於歐洲開放資料 Urban Atlas 的簡化版本)。土地使用指出某一區域用於何種活動,例如住宅或休閒。這是一個多邊形資料集,每個多邊形都有一個標籤,代表巴黎不同區域的土地使用類別。
在本練習中,你會讀取資料、用視覺化方式探索,並計算巴黎地區各土地使用類別的總面積。
已經匯入 GeoPandas 和 matplotlib。
本練習屬於課程
在 Python 中處理地理空間資料
練習說明
- 讀取
'paris_land_use.shp'檔案,並將結果指定給變數land_use。 - 繪製
land_use的圖,使用'class'欄位為多邊形上色,並加入圖例。注意:由於多邊形很多,生成圖形可能需要幾秒鐘。 - 新增一個
'area'欄位,填入每個多邊形的面積。 - 使用
groupby()計算每個'class'的總面積(單位 km²),並印出結果。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import the land use dataset
land_use = geopandas.____
print(land_use.head())
# Make a plot of the land use with 'class' as the color
land_use.plot(____, legend=True, figsize=(15, 10))
plt.show()
# Add the area as a new column
land_use['area'] = ____
# Calculate the total area for each land use class
total_area = land_use.groupby(____)['area'].____() / 1000**2
print(total_area)