Get startedGet started for free

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.

This exercise is part of the course

Working with Geospatial Data in Python

View Course

Exercise 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).

Hands-on interactive exercise

Have a go at this exercise by completing this sample 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(____)
Edit and Run Code