...

/

Solution: Clipping and Merging

Solution: Clipping and Merging

Follow the step-by-step instructions to clip and merge real datasets.

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 datasets
islands = gpd.read_file('minor_islands.geojson')
marine = gpd.read_file('marine_polys.geojson')
# select just the desired seas
black_caspian_seas = marine.query("name == 'Black Sea' or name == 'Caspian Sea'")
# clip the islands to the extents from the desired seas
clipped = islands.clip(black_caspian_seas)
# display the results
ax = 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 ...