檢視疊加結果
現在我們已經把土地使用與行政區這兩個資料集做了疊加,你就能更容易檢視各行政區的土地使用情形。讓我們回到 Muette 這個範例行政區,來檢視該區的土地使用。
GeoPandas 與 Matplotlib 已經匯入。前面練習中 overlay() 函式的結果已存為 combined。
本練習屬於課程
在 Python 中處理地理空間資料
練習說明
- 在
combined這個 GeoDataFrame 中新增一個名為'area'的欄位,內容為每個多邊形的面積。 - 建立名為
land_use_muette的子集,其中'district_name'等於「Muette」。 - 繪製
land_use_muette的圖,並用'class'欄位為多邊形著色。 - 使用
groupby()方法計算land_use_muette各個'class'的總面積,並列印結果。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Print the first rows of the overlay result
print(combined.head())
# Add the area as a column
____ = ____
# Take a subset for the Muette district
land_use_muette = combined[____]
# Visualize the land use of the Muette district
land_use_muette.____(____)
plt.show()
# Calculate the total area for each land use class
print(land_use_muette.____(____)['area'].____() / 1000**2)