CommencerCommencer gratuitement

Shapely's spatial methods

Now we have a shapely Point object for the Eiffel Tower, we can use the different methods available on such a geometry object to perform spatial operations, such as calculating a distance or checking a spatial relationship.

We repeated the construction of eiffel_tower, and also provide the code that extracts one of the neighbourhoods (the Montparnasse district), as well as one of the restaurants located within Paris.

Cet exercice fait partie du cours

Working with Geospatial Data in Python

Afficher le cours

Instructions

  • Check if the Eiffel Tower is located within the Montparnasse district.
  • Check if the Montparnasse district contains the restaurant location.
  • Calculate the distance between the Eiffel Tower and the restaurant (note: in this case, the distance is returned in meters).

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# 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(____)
Modifier et exécuter le code