兩個多邊形的交集
在這個練習中,我們會使用 2 個獨立的多邊形:從 districts 資料集擷取的 Muette 行政區,以及從 land_use 資料集擷取的 Boulogne 綠地(巴黎西側的一座大型公園)。這兩個多邊形已經指定給變數 muette 與 park_boulogne。
我們先把兩個多邊形視覺化。你會看到它們有重疊,但公園並非完全位於 Muette 行政區內。讓我們來找出重疊的部分。
GeoPandas 與 matplotlib 已經匯入。
本練習屬於課程
在 Python 中處理地理空間資料
練習說明
- 在同一張地圖上繪製兩個多邊形,先用肉眼檢視重疊程度。
- 計算
park_boulogne與muette多邊形的交集。 - 列印公園佔該行政區面積的比例。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Plot the two polygons
geopandas.GeoSeries([park_boulogne, muette]).plot(alpha=0.5, color=['green', 'blue'])
plt.show()
# Calculate the intersection of both polygons
intersection = ____
# Plot the intersection
geopandas.GeoSeries([intersection]).plot()
plt.show()
# Print proportion of district area that occupied park
print(____ / ____)