Skip to content

Number of Distinct Classes

João Siqueira edited this page Nov 10, 2026 · 2 revisions

Script: codes/analysis_3_number_of_classes.js. The calculation is in the function getNumberOfClasses.

Description: Counts how many different classes have occupied the pixel over the 40 years. A class that appears in several separate periods counts once.

What it shows: It is a proxy for land use diversity. A pixel with a value of 1 has always been the same class; a higher value means it went through that many categories. In the example, pixel A went through Forest, Pasture, Mosaic of Uses and Soybean (4 classes), and pixel C, which returned to forest, has only 2.

Number of classes on the four example pixels: A 4, B 1, C 2, D 3

Parameters

Set at the top of the script; change them before running.

variable default meaning
asset Collection 10.1 coverage asset the multi-band image read by the script
years 1985 … 2024 years included in the series
bandPrefix 'classification_' band names are bandPrefix + year

Map layers

Besides a land cover reference layer (hidden by default), the script adds:

layer value colors
Number of Classes number of distinct classes grey (few) to dark purple (many)

Pixels with no result are masked and appear transparent.

How to run

Copy the whole script into the Google Earth Engine Code Editor, adjust the parameters and click Run. See Home for the example pixels used in the figure.


← 2. Class Frequency · Home · 4. Number of Changes →

Clone this wiki locally