Get startedGet started for free

Overlaying spatial datasets

1. Overlaying spatial datasets

In the previous exercises, we have learned how to create the intersection of a dataset with a polygon.

2. Intersection with a polygon

For example, as shown in this slide, we have learnt how to intersect a series of countries with a single circle. This is done with the intersection method, which is great for basic operations as it can be used without much overhead. However, the method also has some limitations.

3. Intersection with a polygon

First, it is direct and easy only when we intersect with a single polygon. Intersecting with multiple polygons would require manual repetition and we would lose its original simplicity. Second, the method does not allow to preserve attribute information of the intersecting polygon. For cases where we require a bit more complexity, it is preferable to use the "overlay" operation, instead of the intersection method. Overlay will thus be the focus of this video.

4. Overlaying two datasets

Consider the following simplified example. On the left we see again the 3 countries. On the right we have the plot of a GeoDataFrame with some simplified geologic regions for the same area.

5. Overlaying two datasets

By simply plotting them on top of each other, as shown here, you can see that the polygons of both layers intersect. But now, by overlaying the two layers, we can create a third layer that contains the result of intersecting both layers: all the intersections of each country with each geologic region. We would end up with what is shown here on the right. It keeps only those areas that were included in both layers. This operation is called an intersection overlay, and in GeoPandas we can perform this operation with the geopandas.overlay function. At first sight, you might think this is the same as using the intersection method. Let's dig a bit deeper to find out what is different.

6. Overlay vs intersection

So, first, with the intersection method we only pass a single polygon, in this case only geographic region A. It returns the intersection of each of the three countries with that provided polygon, as shown in the top example. For the first row, this gives an empty polygon. With the overlay method, however, we pass the full GeoDataFrame with all regions to intersect the countries with. The result contains all non-empty intersections of all combinations of countries and geologic regions, as shown in the bottom example. Second, note that the result of the overlay function also keeps the attribute information of both the countries as the geologic regions. That can be very useful for further analysis.

7. Let's practice!

Let's do an exercise on this overlay operation.