НачатьНачать бесплатно

Extract information from raster layer

Let's now extract information from the raster layer, based on a vector file. This functionality is provided by the rasterstats package. Specifically for this exercise, we will determine the vegetation type at all mining sites, by getting the nearest raster pixel value at each point of the mining site dataset.

A subset of the mining sites dataset (mining_sites) is already loaded, and GeoPandas and matplotlib are already imported.

Это упражнение является частью курса

Working with Geospatial Data in Python

Посмотреть курс

Инструкции к упражнению

  • Import the rasterstats package.
  • Extract the nearest raster value for the mining site locations (mining_sites) using the rasterstats.point_query() function, and assign this to a new column 'vegetation'.
  • Make a plot of the mining site data using the 'vegetation' column to color the points. Make sure to add a legend.

Интерактивное практическое упражнение

Попробуйте выполнить это упражнение, дополнив этот пример кода.

# Import the rasterstats package
____

# Extract the nearest value in the raster for all mining sites
vegetation_raster = "central_africa_vegetation_map_foraf.tif"
mining_sites['vegetation'] = ____(____, ____, interpolate='nearest')
print(mining_sites.head())

# Replace numeric vegation types codes with description
mining_sites['vegetation'] = mining_sites['vegetation'].replace(vegetation_types)

# Make a plot indicating the vegetation type
____
plt.show()
Редактировать и запускать код