-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclassification.js
More file actions
41 lines (32 loc) · 1.31 KB
/
classification.js
File metadata and controls
41 lines (32 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var startDate = ee.Date('2016-01-01');
var endDate = ee.Date('2016-12-31');
var Bounds = ee.FeatureCollection('ft:...');
var poly=ee.FeatureCollection('ft:...');
var L8 = ee.ImageCollection('LANDSAT/LC8_L1T');
var composite = ee.Algorithms.Landsat.simpleComposite({
collection: L8.filterDate(startDate, endDate).filterBounds(Bounds),
asFloat: true});
var bands = ['B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B10', 'B11'];
var image = composite.select(bands).clip(Bounds);
var train = image.sampleRegions({
collection: poly,
properties: ['CLASS'],
scale: 30
});
// Train the classifier.
var trained = ee.Classifier.cart().train(train, 'CLASS', bands);
// Classify the image.
var classified = image.classify(trained);
print(classified)
// Create a palette to display the classes.
//var palette =['006400', '32CD32', 'EEE8AA',
// '8B4513', '98FB98', '00FA9A',
// '90EE90', '00008B', 'FF8C00',
// 'ADFF2F', '808080'];
// Display the classification result and the input image.
Map.addLayer(image, {bands: ['B4', 'B3', 'B2'], max: 0.5, gamma: 2});
Map.addLayer(classified, {min: 0, max: 20}, 'Vegetation Type');
var tac = trained.confusionMatrix();
print('Resubstitution error matrix: ', tac);
print('Training overall accuracy: ', tac.accuracy());
print('Training kappa: ', tac.kappa());