ComeçarComece de graça

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.

Este exercício faz parte do curso

Working with Geospatial Data in Python

Ver curso

Instruções do exercício

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

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# 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(____)
Editar e executar o código