Shapely の空間メソッド
エッフェル塔の shapely の Point オブジェクトが用意できたので、距離の計算や空間関係の判定など、ジオメトリオブジェクトで利用できる各種メソッドを使って空間演算を行います。
ここでは eiffel_tower の作成を再掲し、さらに、ある近隣地区(モンパルナス地区)を抽出するコードと、パリ市内にあるレストランの 1 件を取り出すコードも用意しました。
この演習はコースの一部です
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(____)