I'm trying to detect how many times land type has changed between 2001 and 2018 (inclusively).
For example, suppose a pixel that was:
- Forest from 2001 to 2003
- Bare ground from 2003 to 2010
- Agriculture from 2010 to 2015
- City from 2015 to 2018
Since the land use for this pixel changed 3 times, a value of 3 for this pixel would be written to the output image. The resulting image would show which areas changed a lot, and which areas changed less.
I think there must be a function to do this, but I cannot find it.
I've considered writing code that calls subtract
. However, if I do that, I'll need to subtract all land types (17 landtype) between each 2 years. Since there are 18 years of data, that works out to 17 X 17 X 18= 5,202
lines of code.
nsw_border is NSW.Australia shapefile (I got it from the Internet)
var dataset = ee.ImageCollection('MODIS/006/MCD12Q1');
var igbpLandCover = dataset.select('LC_Type1');
var multiband = igbpLandCover.toBands().clip(nsw_border);
var onlycity = multiband; // Just change name of variable
var city2001 = onlycity.select(0);
var city2002 = onlycity.select(1);
var city2003 = onlycity.select(2);
var city2004 = onlycity.select(3);
var city2005 = onlycity.select(4);
var city2006 = onlycity.select(5);
var city2007 = onlycity.select(6);
var city2008 = onlycity.select(7);
var city2009 = onlycity.select(8);
var city2010 = onlycity.select(9);
var city2011 = onlycity.select(10);
var city2012 = onlycity.select(11);
var city2013 = onlycity.select(12);
var city2014 = onlycity.select(13);
var city2015 = onlycity.select(14);
var city2016 = onlycity.select(15);
var city2017 = onlycity.select(16);
var city2018 = onlycity.select(17);
var difer2002_2001 = city2002.subtract(city2001).rename('differ2002_2001');