BaşlayınÜcretsiz başlayın

En yakın restoran ne kadar uzakta?

Şimdi, Eyfel Kulesi'nin yakınındaki restoranlarla ilgilenebiliriz. Bunları keşfetmek için, Eyfel Kulesi'ni ve 1 km içindeki restoranları görselleştirelim.

Bunu yapmak için her restoranın Eyfel Kulesi'ne olan uzaklığını hesaplayabiliriz. Bu sonuca göre, restoran 1 km içindeyse True, değilse False olan bir maske oluşturup bunu restoranlar GeoDataFrame'ini filtrelemek için kullanabiliriz. Son olarak, bu alt kümenin görselleştirmesini yaparız.

restaurants GeoDataFrame'i yüklendi ve eiffel_tower nesnesi oluşturuldu. Ayrıca matplotlib, GeoPandas ve contextily içe aktarıldı.

Bu egzersiz, kursun bir parçasıdır

Python ile Coğrafi Verilerle Çalışma

Kursa Göz Atın

Egzersiz talimatları

  • Her restoran için Eyfel Kulesi'ne olan uzaklığı hesapla ve sonucu dist_eiffel olarak adlandır.
  • En yakın restorana olan uzaklığı yazdır (bu, dist_eiffel değerlerinin minimumudur).
  • restaurants GeoDataFrame'inde Eyfel Kulesi'ne uzaklığı 1 km'den az olan satırları seç (uzaklığın metre cinsinden olduğunu unutma).

Uygulamalı etkileşimli egzersiz

Bu egzersizi bu örnek kodu tamamlayarak deneyin.

# 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()
Kodu Düzenle ve Çalıştır