Mining sites within national parks
For this exercise, let's start with one of the national parks, the Kahuzi-Biega National park (which was extracted from the national_parks
dataset and is provided as the kahuzi
variable).
Which of the mining sites are located within this national park?
And as a second step: can we determine all mining sites that are located within one of the national parks and in which park?
The mining sites (mining_sites
) and national parks (national_parks
) datasets are already loaded, and GeoPandas is already imported.
This exercise is part of the course
Working with Geospatial Data in Python
Exercise instructions
- Use the
within()
method to subset the mining sites (mining_sites
) located in thekahuzi
national park. Call the resultsites_kahuzi
. - Determine for each of the mining sites if and in which national park it is located. This will create a GeoDataFrame similar to
mining_sites
but with an additional column with national park name. Call this resultsites_within_park
. - Count the number of sites in each park by using the
value_counts()
method on the'Name'
column ofsites_within_park
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Extract the single polygon for the Kahuzi-Biega National park
kahuzi = national_parks[national_parks['Name'] == "Kahuzi-Biega National park"].geometry.squeeze()
# Take a subset of the mining sites located within Kahuzi
sites_kahuzi = ____
print(sites_kahuzi)
# Determine in which national park a mining site is located
sites_within_park = geopandas.____(____, ____, op=____, how='inner')
print(sites_within_park.head())
# The number of mining sites in each national park
print(sites_within_park[____].____())