ComeçarComece de graça

Finding the name of the closest National Park

Let's start with a custom query for a single mining site. Here, we will determine the name of the national park that is the closest to the specific mining site.

The datasets on the mining sites (mining_sites) and national parks (national_parks) are already loaded.

Este exercício faz parte do curso

Working with Geospatial Data in Python

Ver curso

Instruções do exercício

  • Select the first element of geometry and assign it to a variable called single_mine.
  • Calculate the distance from each of the national parks to the single_mine. Call the result dist.
  • Obtain the index for the minimum of dist with the idxmin() method.
  • Get the name of the closest national park using the obtained index with the .loc[] attribute, and print the result.

Exercício interativo prático

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

# Get the geometry of the first row
single_mine = mining_sites.____[____]

# Calculate the distance from each national park to this mine
dist = ____

# The index of the minimal distance
idx = dist.____

# Access the name of the corresponding national park
closest_park = national_parks.____[____, '____']
print(closest_park)
Editar e executar o código