開始使用免費開始

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(____)
編輯並執行程式碼