Get startedGet started for free

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.

This exercise is part of the course

Working with Geospatial Data in Python

View Course

Exercise instructions

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

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# 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)
Edit and Run Code