Solution: Overlays
Check your understanding of overlay operations.
We'll cover the following...
Let's take a look at the solution and review the code:
Press + to interact
import geopandas as gpd# open the datasetsbrazil = gpd.read_file('brazil')stations = gpd.read_file('ozone_stations.csv')# create the geometry for the stationsstations['geometry'] = gpd.points_from_xy(x=stations['X'], y=stations['Y'], crs='epsg:4326')# filter just the stations in Brazilbr_stations = stations.query("country == 'Brazil'")# create the coverage area for each stationbr_stations.geometry = br_stations.buffer(5)# project both datasets to equal area CRSbrazil = brazil.to_crs('ESRI:54034')br_stations = br_stations.to_crs('ESRI:54034')# perform an overlay differenceuncovered = brazil.overlay(br_stations, how='difference')# calculate the not covered areancarea = format(round(uncovered.area.sum()/1e6), ',')# plot the resultsax = uncovered.plot(facecolor='green', edgecolor='black')ax.set_ylabel('Latitude (deg)')ax.set_xlabel('Longitude (deg)')ax.set_title(f'Uncovered area is {ncarea} km²')ax.figure.savefig('output/uncovered.png', dpi=300)
Lines 4–5: Open the desired datasets. ...