Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
###############################################################################
# Clip the Data
# --------------
#
# Now that the data are opened as GeoDataFrame objects and in the same
# projection, the data can be clipped! Recall that in this example, the roads
# will be clipped to the United States boundary.
#
# To clip the data, make
# sure you put the object to be clipped as the first argument in
# ``clip_shp()``, followed by the vector object (boundary) to which you want
# the first object clipped. The function will return the clipped GeoDataFrame
# of the object that is being clipped (e.g. roads).
roads_clipped = ec.clip_shp(roads, country_boundary)
# Plot the clipped data
# The plot below shows the results of the clip function applied to the roads
# sphinx_gallery_thumbnail_number = 2
fig, ax = plt.subplots(figsize=(12, 8))
roads_clipped.plot(ax=ax, color="grey")
country_boundary.boundary.plot(ax=ax, color="black")
ax.set_title("Major NA Roads Clipped to US Border", fontsize=20)
ax.set_axis_off()
plt.show()