English | Deutsch
Land cover (ESA WorldCover)¶
What covers the ground? The ESA WorldCover map for 2021 sorts every 10 m pixel into one of eleven classes: tree cover, grassland, cropland, built-up, water and so on. The numbers in the file are class numbers, not measurements.
Download function |
|
|---|---|
Plot function |
|
Source |
ESA WorldCover 2021, version 2 (collection |
Pixel size |
10 m |
Result |
one band of 8-bit integers: the class numbers 10, 20, … 100; 0 is no data. A colour table is stored in the file. |
Clouds |
not affected |
Period |
none needed. The map is for the year 2021; |
Example¶
from cdec import download_land_cover, plot_land_cover
spatial_extent = {"west": 8.721771, "south": 53.025027, "east": 8.904419, "north": 53.114965} # Bremen
path = download_land_cover("data/land_cover_bremen.tif", spatial_extent) # no period needed
plot_land_cover(path)
Bremen, 2021. The legend lists the classes that occur in the picture. © ESA WorldCover project 2021 / Contains modified Copernicus Sentinel data (2021) processed by ESA WorldCover consortium.¶
The classes¶
- cdec.WORLDCOVER_CLASSES: dict[int, str]¶
The classes of the ESA WorldCover map: class number to name.
- cdec.WORLDCOVER_COLORS: dict[int, str]¶
The official WorldCover colour of every class number, as hex code. This is the colour table that
download_land_cover()stores in the GeoTIFF andplot_land_cover()uses.ID
Class
Color
10
Tree cover
#00640020
Shrubland
#ffbb2230
Grassland
#ffff4c40
Cropland
#f096ff50
Built-up
#fa000060
Bare / sparse vegetation
#b4b4b470
Snow and ice
#f0f0f080
Permanent water bodies
#0064c890
Herbaceous wetland
#0096a095
Mangroves
#00cf75100
Moss and lichen
#fae6a0
Things to know¶
Count, do not average. The numbers are labels. The mean of 10 (tree cover) and 50 (built-up) says nothing. Count pixels per class instead:
import numpy as np import rasterio with rasterio.open(path) as src: classes, counts = np.unique(src.read(1), return_counts=True)
Nearest neighbour. The overview levels of the file are made with
overview_resampling="nearest", so no invented in-between classes appear when you zoom out.The colours are stored in the file as a colour table, so programs that read colour tables, such as QGIS, can show the official colours without any setup.
The map is for the year 2021. It is a classification made by an algorithm: it is not perfect, and fine structures can be wrong.
The file uses longitude and latitude (EPSG:4326).
See also¶
Download¶
- cdec.download_land_cover(file_path, spatial_extent, temporal_extent=('2021-01-01T00:00:00Z', '2021-12-31T23:59:59Z'), *, create_cog=True, overview_resampling='nearest')[source]¶
Download the ESA WorldCover 2021 land-cover map at 10 m resolution.
The resulting raster contains integer class IDs in its
MAPband. An ESA WorldCover color table is attached to the GeoTIFF for visualization.- Parameters:
file_path (str | Path) – Destination path of the GeoTIFF file. Missing parent directories are created automatically.
spatial_extent (SpatialExtent) – Area to download: an openEO bounding-box dictionary such as
{"west": 8.7, "south": 53.0, "east": 8.9, "north": 53.1}(degrees, WGS 84), a Shapely geometry, or the path to a GeoJSON file.temporal_extent (TemporalExtent) – Collection period used for the openEO request. The default covers the static 2021 WorldCover product and normally does not need changing. Other years find no data in this collection.
create_cog (bool) – If
True, write a Cloud Optimized GeoTIFF. IfFalse, keep a regular GeoTIFF.overview_resampling (OverviewResampling) – Resampling method used to build COG overview levels.
"nearest"preserves categorical class IDs and should normally not be changed.
- Returns:
Absolute path of the GeoTIFF that was written. The file has one band of 8-bit integers (
uint8): the WorldCover class of every pixel (10, 20, … 100;cdec.WORLDCOVER_CLASSEShas the names). 0 means no data and is declared as the no-data value. The colours of the classes are stored in the file as a colour table. The coordinate system is geographic (EPSG:4326, degrees); the pixel size is 0.000083 degrees, about 10 m.- Return type:
Path
Plot¶
- cdec.plot_land_cover(file_path, *, ax=None, title=None, show=None)[source]¶
Draw the classes of
download_land_cover.Every pixel is one of the WorldCover classes (
cdec.WORLDCOVER_CLASSES) and is drawn in the official colour of its class (cdec.WORLDCOVER_COLORS). The legend lists only the classes that occur in the image. Pixels with another value are transparent.The colours are not read from the colour table inside the file but from
cdec.WORLDCOVER_COLORS, so the picture looks the same for every file.- Parameters:
file_path (str | Path) – The GeoTIFF written by
download_land_cover.ax (Axes | None) – A matplotlib
Axesto draw into.Nonecreates a new figure.title (str | None) – Title of the plot. Default: “Land cover (ESA WorldCover)”. Use
""for no title.show (bool | None) – Call
plt.show()at the end. The default (None) shows the figure only if this function created it.
- Returns:
The axes with the plot, for further changes. The legend is placed to the right of the plot; to save it in a picture file use
plt.savefig("land_cover.png", bbox_inches="tight").- Return type:
matplotlib.axes.Axes
- Raises:
ValueError – If the file does not have exactly one band.