Skip to content

Time Since Last Occurrence

João Siqueira edited this page Nov 10, 2026 · 1 revision

Script: codes/analysis_8_time_since_last.js. The calculation is in the function getTimeSinceLastOccurrence.

Description: Counts the years between the last year in which the pixel was classified as the targetClass and the last year of the series (2024). It is Class Last Year expressed as elapsed time: 2024 − last year. A pixel still in the class in 2024 gets 0, which is kept visible on the map; only pixels never in the class are transparent.

What it shows: How long ago a class left each location: abandoned pasture, for example, and for how long the area has been under another use. Unlike the other analyses, 0 is a result, not an absence: it marks where the class is still present. In the example, pixel C left pasture 14 years ago (last pasture year 2010) and pixel D 6 years ago (2018); pixel A is still pasture (0); pixel B was never pasture.

Time since the last occurrence on the four example pixels: A 0 years, B masked, C 14 years, D 6 years

Parameters

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

variable default meaning
targetClass 15 (Pasture) class of interest, a MapBiomas legend code
asset Collection 10.1 coverage asset the multi-band image read by the script
years 1985 … 2024 years included in the series; the last one is the reference year
bandPrefix 'classification_' band names are bandPrefix + year

Map layers

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

layer value colors
Class 15 Years Since Last years since the last year in the class; 0 if still in it dark red (recent) to light yellow (long ago)

Pixels never in the class 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.


← 7. Class Last Year · Home · 9. Accumulated Class →

Clone this wiki locally