Get startedGet started for free

Additional spatial operations

1. Additional spatial operations

We already have seen quite a few spatial operations throughout this course. Since these are the "bread and butter" of many real world analyses, in this video we will do a quick recap of those we've covered, and we will see a few more.

2. Overview of spatial operations

We have seen a set of methods that check for spatial relationships, such as intersects, within, contains, etc. Those methods always return boolean objects: a series of True and False values. We have also seen methods that create new geometries by taking the intersection, union, or difference of two geometries. All these methods are available both as methods on a single shapely geometry, and as element-wise methods on a GeoDataFrame or GeoSeries. In addition, we have seen two more advanced functions to spatially combine two GeoDataFrames that are related to those operations. First, the sjoin or spatial join function, that is used to join attribute information based on a given spatial relationship. And second, the overlay function that combines two GeoDataFrames by calculating all intersections, unions or differences between all geometries of both datasets. Now let's see a couple more which are also commonly used.

3. Unary union

For the union operation, there is one special case worth mentioning. Before, we have seen how to take the union of two individual geometries. But a common use case is where you want to take the union of a whole series of geometries. For example, consider all the countries of Africa shown here. Now we might want to compute the union of all the countries of this GeoSeries.

4. Unary union

For this, we can use the unary_union attribute, which returns a single geometry containing the full extent of all the geometries involved in the operation.

5. Buffer operation

Another very common case is the buffer. This operation creates a buffer, or a polygon around a given geometry covering all the area within a specified distance from the original geometry. Let's clarify this with an example. Consider this point on the screen.

6. Buffer operation

The buffer operation will create a polygon consisting of the point itself and the area around it within the specified distance. In case of a point, the buffer is a circular polygon. The python code is shown below the circle.

7. Buffer operation

The same can be done for lines or even polygons. In each case, the result is a new polygon. Note that the buffer is not only the new, light blue area, but instead it covers both the original (dark blue) object as well as the light blue polygon. The examples we showed here are for single shapely geometries. But again, the equivalent method on a GeoSeries will create a buffer for each geometry element-wise. Those buffer operations are typically used in analyses based on proximity.

8. Let's practice!

Let's now apply those spatial operations on the mining site data.