Geographic Information Systems Asked by Elemelon on February 25, 2021
Once exporting my work the graph seems to show the number 8
instead of the label built up area. What is the problem?
This is my code:
var image = ee.Image(ee.ImageCollection('LANDSAT/LT05/C01/T1_SR')
// Filter to get only images under the region of interest.
.filterBounds(roi)
// Filter to get only one year of images.
.filterDate('1986-01-01', '1986-12-30')
// Sort by scene cloudiness, ascending.
.sort('CLOUD_COVER')
// Get the first (least cloudy) scene.
.first());
Map.addLayer(image, {bands: ['B5', 'B4', 'B3'], max: 0.5, gamma: 2}, "L8 Image");
// Merge points together
var newfc = Water.merge(naturalwoodlands).merge(plantedforest).merge(builtuparea).merge(cultivatedland).merge(grassland).merge(barrenland).merge(saltmarsh);
print(newfc, 'newfc');
// Select the bands to be used in training
var bands = ['B2', 'B3', 'B4', 'B5', 'B6', 'B7'];
// Sample the input imagery to get a FeatureCollection of training data.
var training = image.select(bands).sampleRegions({
collection: newfc,
properties: ['landuse'],
scale: 30 // should reflect the scale of your imagery
});
// Make a classifier and train it.
var classifier = ee.Classifier.randomForest(10).train({
features: training,
classProperty: 'landuse',
inputProperties: bands
});
// Classify the input imagery.
var classified = image.select(bands).classify(classifier).aside(print);
// Define a palette for the Land Use classification.
var palette = [
'#0a9917', // naturalwoodlands(0)
'#00f7f7', // water(1)
'#fffcb0', // cultivatedland(2)
'#d7d8ff', // builtuparea(3)
'#1aff0b', // plantedforest(4)
'#e766ff' , // grassland(5)
'#1612f7', // barrenland(6)
'#a054ff',// saltmarsh(7)
];
// Display th#ff4b38e classification result and the input image.
Map.setCenter(23.054, -34.0482);
Map.addLayer(classified, {min: 0, max: 6, palette: palette}, 'Land Cover Classification');
// Get a confusion matrix representing resubstitution accuracy.
var trainAccuracy = classifier.confusionMatrix();
print('Resubstitution error matrix: ', trainAccuracy);
print('Training overall accuracy: ', trainAccuracy.accuracy());
// var ghnp = ee.FeatureCollection('ft:1Kh5uxAdbnuF77vydlLPCAOQ-A7HgLxyYFyI4QnnT', 'geometry');
// Map.addLayer(ghnp, null, 'roi');
var areaChart = ui.Chart.image.byClass({
image: ee.Image.pixelArea().divide(1000000).addBands(classified),
classBand: 'classification',
region: geometry,
scale: 30,
reducer: ee.Reducer.sum(),
classLabels: ['water', 'naturalwoodlands','plantedforest','builtuparea','cultivatedland','grassland','barrenland','saltmarsh']
}).setOptions({
hAxis: {title: 'Classes'},
vAxis: {title: 'Area sqkm'},
title: 'A histogram showing area by class',
series: {
0: { color: 'blue' },
1: { color: 'green' },
2: { color: 'brown' },
3: { color: 'gray' },
4: { color: 'yellow' },
5: { color: 'purple' },
6: { color: 'pink' },
7: { color: 'black' },
}
});
print(areaChart);
var exportAccuracy = ee.Feature(null, {matrix: trainAccuracy.array()})
// Export the FeatureCollection.
Export.table.toDrive({
collection: ee.FeatureCollection(exportAccuracy),
description: 'exportAccuracy',
fileFormat: 'CSV'
});
// Get a confusion matrix representing resubstitution accuracy.
print('RF error matrix: ', classifier.confusionMatrix());
print('RF accuracy: ', classifier.confusionMatrix().accuracy());
Export.image.toDrive({
image: classified,
description: 'LC_2018',
scale: 30,
region: geometry,
maxPixels: 130000000000,
});
var exportAccuracy = ee.Feature(null, {matrix: trainAccuracy.array()})
// Export the FeatureCollection.
Export.table.toDrive({
collection: ee.FeatureCollection(exportAccuracy),
description: 'exportAccuracy',
fileFormat: 'CSV'
});
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP