1. Learn
  2. /
  3. Courses
  4. /
  5. Working with Geospatial Data in Python

Exercise

Applying a custom operation to each geometry

Now we know how to get the closest national park for a single point, let's do this for all points. For this, we are first going to write a function, taking a single point as argument and returning the desired result. Then we can use this function to apply it to all points.

The datasets on the mining sites (mining_sites) and national parks (national_parks) are already loaded. The single mining site from the previous exercises is already defined as single_mine.

Instructions

100 XP
  • Create a function closest_national_park() that performs the analysis you did in the previous exercise: given a single point and all national parks, return the name of the closest national park.
  • As a test, call this function on the single point (single_mine) and print the result. Is it the same as before ("Virunga National park")?
  • Apply this function to all points of mining_sites and assign the result to a column called 'closest_park'.