In this tutorial we will learn how to:
- Define hand-located points to train a classifier.
- Classify the training points into different classes (Urban, Vegetation, Water, and Bare Land)
- Merge the four geometry layers into a single Feature Collection.
- Sample the composite to generate training data. Note that the class label is stored in the ‘landcover’ property.
- Train a CART classifier.
- Split the data into 70% training, 30% testing. and classify the composite.
- Print the confusion matrix.
- And finally determine the Land Cover Change between 1999 and 2018.
Data Used
USGS Landsat 8 Collection 1 Tier 1 and Real-Time data TOA Reflectance
Landsat 8 Collection 1 Tier 1 and Real-Time data calibrated top-of-atmosphere (TOA) reflectance. Calibration coefficients are extracted from the image metadata. See Chander et al. (2009) for details on the TOA computation. The Landsat 8 images are of 30 m and 16 days spatial and temporal resolutions respectively.
USGS Landsat 7 Collection 1 Tier 1 TOA Reflectance
Landsat 7 Collection 1 Tier 1 calibrated top-of-atmosphere (TOA) reflectance. Calibration coefficients are extracted from the image metadata. See Chander et al. (2009) for details on the TOA computation. The Landsat 7 images are of 30 m and 16 days spatial and temporal resolutions respectively.
Here is the code:
Define hand-located points to train a classifier and classify the training points into different classes (Urban, Vegetation, Water, and Bare Land)
Map.setOptions('HYBRID')
// Create a circle by drawing a 25000 meter buffer around a point.
var roi = ee.Geometry.Point([73.0173, 19.0768]).buffer(35000);
Map.addLayer(roi, {}, 'Mumbai');
Map.centerObject(roi,10);
//Define landcover classes
var urban = /* color: #ff0000 */ee.FeatureCollection(
[ee.Feature(
ee.Geometry.Point([72.844901, 19.013206]),
{
"landcover": 0,
"system:index": "0"
}),
ee.Feature(
ee.Geometry.Point([72.894259, 19.109303]),
{
"landcover": 0,
"system:index": "1"
}),
ee.Feature(
ee.Geometry.Point([72.848565, 19.013201]),
{
"landcover": 0,
"system:index": "2"
}),
ee.Feature(
ee.Geometry.Point([72.8398, 19.012868]),
{
"landcover": 0,
"system:index": "3"
}),
ee.Feature(
ee.Geometry.Point([72.83634, 19.013371]),
{
"landcover": 0,
"system:index": "4"
}),
ee.Feature(
ee.Geometry.Point([72.818259, 19.011052]),
{
"landcover": 0,
"system:index": "5"
}),
ee.Feature(
ee.Geometry.Point([72.821955, 19.01089]),
{
"landcover": 0,
"system:index": "6"
}),
ee.Feature(
ee.Geometry.Point([72.815845, 19.009667]),
{
"landcover": 0,
"system:index": "7"
}),
ee.Feature(
ee.Geometry.Point([72.814921, 19.00633]),
{
"landcover": 0,
"system:index": "8"
}),
ee.Feature(
ee.Geometry.Point([72.814117, 19.005417]),
{
"landcover": 0,
"system:index": "9"
}),
ee.Feature(
ee.Geometry.Point([72.814117, 19.005417]),
{
"landcover": 0,
"system:index": "10"
}),
ee.Feature(
ee.Geometry.Point([72.826032, 18.928838]),
{
"landcover": 0,
"system:index": "11"
}),
ee.Feature(
ee.Geometry.Point([72.833048, 18.928879]),
{
"landcover": 0,
"system:index": "12"
}),
ee.Feature(
ee.Geometry.Point([72.822634, 18.913188]),
{
"landcover": 0,
"system:index": "13"
}),
ee.Feature(
ee.Geometry.Point([72.815704, 18.91106]),
{
"landcover": 0,
"system:index": "14"
}),
ee.Feature(
ee.Geometry.Point([72.906783, 19.018533]),
{
"landcover": 0,
"system:index": "15"
}),
ee.Feature(
ee.Geometry.Point([72.905608, 19.018447]),
{
"landcover": 0,
"system:index": "16"
}),
ee.Feature(
ee.Geometry.Point([72.877128, 19.07619]),
{
"landcover": 0,
"system:index": "17"
}),
ee.Feature(
ee.Geometry.Point([72.875993, 19.075746]),
{
"landcover": 0,
"system:index": "18"
}),
ee.Feature(
ee.Geometry.Point([72.87467, 19.098952]),
{
"landcover": 0,
"system:index": "19"
}),
ee.Feature(
ee.Geometry.Point([72.871794, 19.094166]),
{
"landcover": 0,
"system:index": "20"
}),
ee.Feature(
ee.Geometry.Point([72.878661, 19.09593]),
{
"landcover": 0,
"system:index": "21"
}),
ee.Feature(
ee.Geometry.Point([72.854045, 19.090488]),
{
"landcover": 0,
"system:index": "22"
}),
ee.Feature(
ee.Geometry.Point([72.871495, 19.082256]),
{
"landcover": 0,
"system:index": "23"
})]),
vegetation = /* color: #3b8b00 */ee.FeatureCollection(
[ee.Feature(
ee.Geometry.Point([72.870052, 19.082555]),
{
"landcover": 1,
"system:index": "0"
}),
ee.Feature(
ee.Geometry.Point([72.872654, 19.082636]),
{
"landcover": 1,
"system:index": "1"
}),
ee.Feature(
ee.Geometry.Point([72.865031, 19.082712]),
{
"landcover": 1,
"system:index": "2"
}),
ee.Feature(
ee.Geometry.Point([72.862968, 19.08166]),
{
"landcover": 1,
"system:index": "3"
}),
ee.Feature(
ee.Geometry.Point([72.8577816, 19.08322]),
{
"landcover": 1,
"system:index": "4"
}),
ee.Feature(
ee.Geometry.Point([72.921573, 19.02459]),
{
"landcover": 1,
"system:index": "5"
}),
ee.Feature(
ee.Geometry.Point([72.911617, 19.024895]),
{
"landcover": 1,
"system:index": "6"
}),
ee.Feature(
ee.Geometry.Point([72.874259, 19.009324]),
{
"landcover": 1,
"system:index": "7"
}),
ee.Feature(
ee.Geometry.Point([72.801724, 18.957517]),
{
"landcover": 1,
"system:index": "8"
}),
ee.Feature(
ee.Geometry.Point([72.803097, 18.957989]),
{
"landcover": 1,
"system:index": "9"
}),
ee.Feature(
ee.Geometry.Point([72.799326, 18.957847]),
{
"landcover": 1,
"system:index": "10"
}),
ee.Feature(
ee.Geometry.Point([72.91381, 19.20591]),
{
"landcover": 1,
"system:index": "11"
}),
ee.Feature(
ee.Geometry.Point([72.93763, 19.20388]),
{
"landcover": 1,
"system:index": "12"
}),
ee.Feature(
ee.Geometry.Point([72.89495, 19.18374]),
{
"landcover": 1,
"system:index": "13"
}),
ee.Feature(
ee.Geometry.Point([73.039387, 19.064548]),
{
"landcover": 1,
"system:index": "14"
}),
ee.Feature(
ee.Geometry.Point([73.042268, 19.064756]),
{
"landcover": 1,
"system:index": "15"
}),
ee.Feature(
ee.Geometry.Point([72.942467, 19.134482]),
{
"landcover": 1,
"system:index": "16"
}),
ee.Feature(
ee.Geometry.Point([72.921375, 19.023596]),
{
"landcover": 1,
"system:index": "17"
}),
ee.Feature(
ee.Geometry.Point([72.916397, 19.022795]),
{
"landcover": 1,
"system:index": "18"
}),
ee.Feature(
ee.Geometry.Point([72.882451, 19.017682]),
{
"landcover": 1,
"system:index": "19"
}),
ee.Feature(
ee.Geometry.Point([72.871845, 19.008351]),
{
"landcover": 1,
"system:index": "20"
}),
ee.Feature(
ee.Geometry.Point([72.86342, 19.005717]),
{
"landcover": 1,
"system:index": "21"
}),
ee.Feature(
ee.Geometry.Point([72.856597, 19.00591]),
{
"landcover": 1,
"system:index": "22"
})]),
water = /* color: #0300ff */ee.FeatureCollection(
[ee.Feature(
ee.Geometry.Point([72.87995, 18.96889]),
{
"landcover": 2,
"system:index": "0"
}),
ee.Feature(
ee.Geometry.Point([72.87514, 18.94795]),
{
"landcover": 2,
"system:index": "1"
}),
ee.Feature(
ee.Geometry.Point([72.80836, 18.93999]),
{
"landcover": 2,
"system:index": "2"
}),
ee.Feature(
ee.Geometry.Point([72.7828, 19]),
{
"landcover": 2,
"system:index": "3"
}),
ee.Feature(
ee.Geometry.Point([72.85844, 19.054791]),
{
"landcover": 2,
"system:index": "4"
}),
ee.Feature(
ee.Geometry.Point([72.853805, 19.053979]),
{
"landcover": 2,
"system:index": "5"
}),
ee.Feature(
ee.Geometry.Point([72.866444, 19.055298]),
{
"landcover": 2,
"system:index": "6"
}),
ee.Feature(
ee.Geometry.Point([72.835697, 19.048719]),
{
"landcover": 2,
"system:index": "7"
}),
ee.Feature(
ee.Geometry.Point([72.878906, 19.085985]),
{
"landcover": 2,
"system:index": "8"
}),
ee.Feature(
ee.Geometry.Point([72.881857, 19.083947]),
{
"landcover": 2,
"system:index": "9"
}),
ee.Feature(
ee.Geometry.Point([72.92459, 19.075277]),
{
"landcover": 2,
"system:index": "10"
}),
ee.Feature(
ee.Geometry.Point([72.95669, 19.06718]),
{
"landcover": 2,
"system:index": "11"
}),
ee.Feature(
ee.Geometry.Point([72.95989, 18.99842]),
{
"landcover": 2,
"system:index": "12"
}),
ee.Feature(
ee.Geometry.Point([72.824017, 19.169877]),
{
"landcover": 2,
"system:index": "13"
}),
ee.Feature(
ee.Geometry.Point([72.807762, 19.153219]),
{
"landcover": 2,
"system:index": "14"
}),
ee.Feature(
ee.Geometry.Point([72.99832, 19.25497]),
{
"landcover": 2,
"system:index": "15"
}),
ee.Feature(
ee.Geometry.Point([73.027946, 19.199556]),
{
"landcover": 2,
"system:index": "16"
}),
ee.Feature(
ee.Geometry.Point([72.916244, 19.289059]),
{
"landcover": 2,
"system:index": "17"
}),
ee.Feature(
ee.Geometry.Point([72.82676, 19.32242]),
{
"landcover": 2,
"system:index": "18"
}),
ee.Feature(
ee.Geometry.Point([72.77527, 19.32113]),
{
"landcover": 2,
"system:index": "19"
}),
ee.Feature(
ee.Geometry.Point([72.74557, 19.32404]),
{
"landcover": 2,
"system:index": "20"
}),
ee.Feature(
ee.Geometry.Point([72.906202, 19.126508]),
{
"landcover": 2,
"system:index": "21"
}),
ee.Feature(
ee.Geometry.Point([72.89682, 19.12607]),
{
"landcover": 2,
"system:index": "22"
}),
ee.Feature(
ee.Geometry.Point([72.904672, 19.124805]),
{
"landcover": 2,
"system:index": "23"
}),
ee.Feature(
ee.Geometry.Point([72.923887, 19.026777]),
{
"landcover": 2,
"system:index": "24"
}),
ee.Feature(
ee.Geometry.Point([72.922154, 19.020386]),
{
"landcover": 2,
"system:index": "25"
}),
ee.Feature(
ee.Geometry.Point([72.846662, 19.267797]),
{
"landcover": 2,
"system:index": "26"
}),
ee.Feature(
ee.Geometry.Point([72.7564, 19.1997]),
{
"landcover": 2,
"system:index": "27"
}),
ee.Feature(
ee.Geometry.Point([72.7472, 19.2473]),
{
"landcover": 2,
"system:index": "28"
}),
ee.Feature(
ee.Geometry.Point([72.7513, 19.2528]),
{
"landcover": 2,
"system:index": "29"
}),
ee.Feature(
ee.Geometry.Point([72.8957, 18.8632]),
{
"landcover": 2,
"system:index": "30"
})]);

Determine the Land Cover in 1999
////////////////////////////////////////////
// Landcover 1999
///////////////////////////////////////////
// Load the Landsat 5 scaled radiance image collection.
var landsatCollection1 = ee.ImageCollection('LANDSAT/LE07/C01/T1')
.filterDate('1999-01-01', '1999-12-31');
// Make a cloud-free composite.
var composite = ee.Algorithms.Landsat.simpleComposite({
collection: landsatCollection1,
asFloat: true
});
// Merge the three geometry layers into a single FeatureCollection.
var newfc_1999 = urban.merge(vegetation).merge(water);
// Use these bands for classification.
var bands = ['B2', 'B3', 'B4', 'B5', 'B7'];
// The name of the property on the points storing the class label.
var classProperty = 'landcover';
// Sample the composite to generate training data. Note that the
// class label is stored in the 'landcover' property.
var training = composite.select(bands).sampleRegions({
collection: newfc_1999,
properties: [classProperty],
scale: 30
});
// Train a CART classifier.
var classifier = ee.Classifier.cart().train({
features: training,
classProperty: classProperty,
});
// Print some info about the classifier (specific to CART).
print('CART, explained', classifier.explain());
// Classify the composite.
var classified_1999 = composite.classify(classifier);
//Map.centerObject(newfc_1999);
Map.addLayer(classified_1999.clip(roi), {
min: 0, max: 2, palette: ['red','green','blue']}, 'LandCover 1999');
// Optionally, do some accuracy assessment. Fist, add a column of
// random uniforms to the training dataset.
var withRandom = training.randomColumn('random');
// We want to reserve some of the data for testing, to avoid overfitting the model.
var split = 0.7; // Roughly 70% training, 30% testing.
var trainingPartition = withRandom.filter(ee.Filter.lt('random', split));
var testingPartition = withRandom.filter(ee.Filter.gte('random', split));
// Trained with 70% of our data.
var trainedClassifier = ee.Classifier.gmoMaxEnt().train({
features: trainingPartition,
classProperty: classProperty,
inputProperties: bands
});
// Classify the test FeatureCollection.
var test = testingPartition.classify(trainedClassifier);
// Print the confusion matrix.
var confusionMatrix_1999 = test.errorMatrix(classProperty, 'classification');
print('Confusion Matrix 1999', confusionMatrix_1999);

Determine the Land Cover in 2018
////////////////////////////////////////////////////////////////
// Landcover 2018
//////////////////////////////////////////////////////////////
// Load the Landsat 8 scaled radiance image collection.
var landsatCollectionL8 = ee.ImageCollection('LANDSAT/LC08/C01/T1')
.filterDate('2018-01-01', '2018-12-31');
// Make a cloud-free composite.
var composite = ee.Algorithms.Landsat.simpleComposite({
collection: landsatCollectionL8,
asFloat: true
});
// Merge the three geometry layers into a single FeatureCollection.
var newfc_2018 = urban.merge(vegetation).merge(water);
// Use these bands for classification.
var bands = ['B2', 'B3', 'B4', 'B5', 'B6', 'B7'];
// The name of the property on the points storing the class label.
var classProperty = 'landcover';
// Sample the composite to generate training data. Note that the
// class label is stored in the 'landcover' property.
var training = composite.select(bands).sampleRegions({
collection: newfc_2018,
properties: [classProperty],
scale: 30
});
// Train a CART classifier.
var classifier = ee.Classifier.cart().train({
features: training,
classProperty: classProperty,
});
// Print some info about the classifier (specific to CART).
print('CART, explained', classifier.explain());
// Classify the composite.
var classified_2018 = composite.classify(classifier);
//Map.centerObject(newfc_2018);
Map.addLayer(classified_2018.clip(roi), {
min: 0, max: 2, palette: ['red','green','blue']},'LandCover 2018');
// Optionally, do some accuracy assessment. Fist, add a column of
// random uniforms to the training dataset.
var withRandom = training.randomColumn('random');
// We want to reserve some of the data for testing, to avoid overfitting the model.
var split = 0.7; // Roughly 70% training, 30% testing.
var trainingPartition = withRandom.filter(ee.Filter.lt('random', split));
var testingPartition = withRandom.filter(ee.Filter.gte('random', split));
// Trained with 70% of our data.
var trainedClassifier = ee.Classifier.gmoMaxEnt().train({
features: trainingPartition,
classProperty: classProperty,
inputProperties: bands
});
// Classify the test FeatureCollection.
var test = testingPartition.classify(trainedClassifier);
// Print the confusion matrix.
var confusionMatrix_2018 = test.errorMatrix(classProperty, 'classification');
print('Confusion Matrix 2018', confusionMatrix_2018);
Determine the Land Cover Change between 1999 and 2018
// Determine Land Cover Change between 1999 and 2018
var lulc = classified_2018.add(classified_1999)
Map.addLayer(lulc.clip(roi),{
min: 0, max: 2, palette: ['green','red','yellow']},'Land Cover Change Between 1999 and 2018');
//print(lulc)
Add Title and Legends
////////////////////////////////////////////////////////////////
/************************ Title ****************************/
/////////////////////////////////////////////////////////////////
Map.add(ui.Label(
'2018 Land Cover Map of Mumbai', {
fontWeight: 'bold', BackgroundColor: 'FBF9F5',fontSize: '14px'}));
/////////////////////////////////////////////////////////////
/************************ legend ****************************/
//////////////////////////////////////////////////////////////
var names = ['Urban', 'Vegetation', 'Water' ];
var values = [ '1', '2', '3' ];
var legendsPalette = ['F93107','04FD0A','040AFD'];
// set position of panel
var legend = ui.Panel({style: { position: 'bottom-center', padding: '8px 15px'}});
// Create legend title
var legendTitle = ui.Label({value: '1999 Land Cover Legends ',style: {
fontWeight: 'bold', fontSize: '18px', margin: '0 0 4px 0', padding: '0' }});
// Add the title to the panel
legend.add(legendTitle);
var makeRow = function(color, name) {
// Create the label that is actually the colored box.
var colorBox = ui.Label({
style: {
backgroundColor: '#' + color, padding: '8px',margin: '0 0 4px 0'} });
// Create the label filled with the description text.
var description = ui.Label({
value: name, style: {margin: '0 0 4px 6px'}});
// return the panel
return ui.Panel({
widgets: [colorBox, description],layout: ui.Panel.Layout.Flow('horizontal')})};
// Add color and and names
for (var i = 0; i < 3; i++) {
legend.add(makeRow(legendsPalette[i], names[i]));
}
// Add the legend to the map.
Map.add(legend);

I m a student I m from Senegal but I study Production and management of geospatial information to Obafemi Owolowo University in Nigeira and I m very interested by GEE.
Dinesh these are great tutorials, however was wondering if you could do one on how to calculate PM2.5 from satellite data. Thanks
This was Nice tutorials very illustrated thank
Please make a video tutorial of this which will be very helpful for beginner like me thank you
apurbasarkar.ugb@gmail.com