Get Started

Import and plot raster data

In this exercise, we are going to use a raster dataset of the vegetation types map (available from http://www.wri.org). The raster values take a set of discrete values indicating the type of vegetation. Let's start with reading the data and plotting it together with the mining site data.

The mining sites dataset (mining_sites) is already loaded, and GeoPandas and matplotlib are already imported.

This is a part of the course

“Working with Geospatial Data in Python”

View Course

Exercise instructions

  • Import the rasterio package.
  • Open the vegetation map geotiff file ("central_africa_vegetation_map_foraf.tif") and assign it to a variable src.
  • Plot the raster dataset using the rasterio.plot.show() function and add the mining site locations in red and marker size of 1.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Import the rasterio package
____

# Open the raster dataset
src = rasterio.____("central_africa_vegetation_map_foraf.tif")

# Import the plotting functionality of rasterio
import rasterio.plot

# Plot the raster layer with the mining sites
ax = rasterio.plot.show(____)
mining_sites.plot(____)
plt.show()

This exercise is part of the course

Working with Geospatial Data in Python

IntermediateSkill Level
4.3+
8 reviews

This course will show you how to integrate spatial data into your Python Data Science workflow.

In this final chapter, we leave the Paris data behind us, and apply everything we have learnt up to now on a brand new dataset about artisanal mining sites in Eastern Congo. Further, you will still learn some new spatial operations, how to apply custom spatial operations, and you will get a sneak preview into raster data.

Exercise 1: Introduction to the datasetExercise 2: Import and explore the dataExercise 3: Convert to common CRS and save to a fileExercise 4: Styling a multi-layered plotExercise 5: Additional spatial operationsExercise 6: Buffer around a pointExercise 7: Mining sites within national parksExercise 8: Applying custom spatial operationsExercise 9: Finding the name of the closest National ParkExercise 10: Applying a custom operation to each geometryExercise 11: Working with raster dataExercise 12: Import and plot raster data
Exercise 13: Extract information from raster layerExercise 14: The end

What is DataCamp?

Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.

Start Learning for Free