探索土地利用数据集
在接下来的练习中,我们先引入一个新数据集:关于巴黎土地利用的数据集(基于欧洲开放的 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)