Repository navigation
Number of Distinct Classes
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.
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
|
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.
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.