Solution: Clipping and Merging
Follow the step-by-step instructions to clip and merge real datasets.
We'll cover the following...
Solution: Spatial clipping
Let's take a look at the solution for the DataFrame clipping challenge and review the code:
Press + to interact
import geopandas as gpd# open the datasetsislands = gpd.read_file('minor_islands.geojson')marine = gpd.read_file('marine_polys.geojson')# select just the desired seasblack_caspian_seas = marine.query("name == 'Black Sea' or name == 'Caspian Sea'")# clip the islands to the extents from the desired seasclipped = islands.clip(black_caspian_seas)# display the resultsax = clipped.plot(edgecolor='red', linewidth=3)black_caspian_seas.plot(ax=ax, facecolor='none')ax.set_ylabel('Latitude (degrees)')ax.set_xlabel('Longitude (degrees)')ax.figure.savefig('output/clipping.png', dpi=300)
In line 8, we select ...