开始使用免费开始使用

最近的餐馆有多远?

现在,我们想查看埃菲尔铁塔附近的餐馆。为便于探索,请将埃菲尔铁塔本身以及 1 km 范围内的餐馆可视化。

为此,您可以计算每家餐馆到埃菲尔铁塔的距离。基于该结果,创建一个布尔掩码:餐馆在 1 km 内为 True,否则为 False,并用它来筛选 restaurants 这个 GeoDataFrame。最后,对该子集进行可视化。

restaurants GeoDataFrame 已载入,eiffel_tower 对象也已创建。此外,matplotlib、GeoPandas 和 contextily 已导入。

本练习是课程的一部分

在 Python 中处理地理空间数据

查看课程

练习说明

  • 计算每家餐馆到埃菲尔铁塔的距离,并将结果命名为 dist_eiffel
  • 打印最近餐馆的距离(即 dist_eiffel 的最小值)。
  • restaurants GeoDataFrame 中选择到埃菲尔铁塔距离小于 1 km 的行(注意,距离单位为米)。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# The distance from each restaurant to the Eiffel Tower
dist_eiffel = ____

# The distance to the closest restaurant
print(dist_eiffel.____)

# Filter the restaurants for closer than 1 km
restaurants_eiffel = ____

# Make a plot of the close-by restaurants
ax = restaurants_eiffel.plot()
geopandas.GeoSeries([eiffel_tower]).plot(ax=ax, color='red')
contextily.add_basemap(ax)
ax.set_axis_off()
plt.show()
编辑并运行代码