CommencerCommencer gratuitement

Intersection of two polygons

For this exercise, we are going to use 2 individual polygons: the district of Muette extracted from the districts dataset, and the green urban area of Boulogne, a large public park in the west of Paris, extracted from the land_use dataset. The two polygons have already been assigned to the muette and park_boulogne variables.

We first visualize the two polygons. You will see that they overlap, but the park is not fully located in the district of Muette. Let's determine the overlapping part.

GeoPandas and matplotlib and are already imported.

Cet exercice fait partie du cours

Working with Geospatial Data in Python

Afficher le cours

Instructions

  • Plot the two polygons in a single map to examine visually the degree of overlap
  • Calculate the intersection of the park_boulogne and muette polygons.
  • Print the proportion of the area of the district that is occupied by the park.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Plot the two polygons
geopandas.GeoSeries([park_boulogne, muette]).plot(alpha=0.5, color=['green', 'blue'])
plt.show()

# Calculate the intersection of both polygons
intersection = ____

# Plot the intersection
geopandas.GeoSeries([intersection]).plot()
plt.show()

# Print proportion of district area that occupied park
print(____ / ____)
Modifier et exécuter le code