开始使用免费开始使用

Shapely 的空间方法

现在我们已经有埃菲尔铁塔的 shapely Point 对象,您可以在该几何对象上使用多种方法来执行空间操作,例如计算距离或检查空间关系。

我们重复构建了 eiffel_tower,并提供了提取其中一个街区(蒙帕纳斯区)的代码,以及位于巴黎的一家餐馆的位置。

本练习是课程的一部分

在 Python 中处理地理空间数据

查看课程

练习说明

  • 检查埃菲尔铁塔是否位于蒙帕纳斯区内。
  • 检查蒙帕纳斯区是否包含该餐馆位置。
  • 计算埃菲尔铁塔与该餐馆之间的距离(注意:在此情况下,距离以米为单位返回)。

交互式实操练习

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

# Construct a point object for the Eiffel Tower
eiffel_tower = Point(255422.6, 6250868.9)

# Accessing the Montparnasse geometry (Polygon) and restaurant
district_montparnasse = districts.loc[52, 'geometry']
resto = restaurants.loc[956, 'geometry']

# Is the Eiffel Tower located within the Montparnasse district?
print(____)

# Does the Montparnasse district contains the restaurant?
print(____)

# The distance between the Eiffel Tower and the restaurant?
print(____)
编辑并运行代码