Geographic Information Systems Asked on February 14, 2021
In the below code, Tasseled Cap algorithm computed using array based computation but returns error and I don’t know how can I solve this:
code link: https://code.earthengine.google.com/7a54500cb06ec88d6ffc6b623965de7c
Map.centerObject(table);
Map.addLayer(table);
var lc8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_SR")
.filterDate('2018-01-01','2020-01-01')
.filterBounds(table)
.filter(ee.Filter.calendarRange(7,9,'month'))
.filter(ee.Filter.lt('CLOUD_COVER',10))
.map(function(img){
var bands = img.select('B[2-7]').multiply(0.0001).clip(table);
return bands.copyProperties(img,['system:time_start','system:time_end',
'system:index'])
}).median();
print(lc8);
Map.addLayer(lc8,{bands:['B5','B4','B3']},'lc8',false);
var coefficients = [
[0.3029, 0.2786, 0.4733, 0.5599, 0.508, 0.1872],
[-0.2941, -0.243, -0.5424, 0.7276, 0.0713, -0.1608],
[0.1511, 0.1973, 0.3283, 0.3407, -0.7117, -0.4559],
[-0.8239, 0.0849, 0.4396, -0.058, 0.2013, -0.2773],
[-0.3294, 0.0557, 0.1056, 0.1855, -0.4349, 0.8085],
[0.1079, -0.9023, 0.4119, 0.0575, -0.0259, 0.0252]];
var bands = ['B2','B3','B4','B5','B6','B7'];
var arrayImage1D = lc8.select(bands).toArray();
print(arrayImage1D)
var arrayImage2D = arrayImage1D.toArray(1);
var componentImages = ee.Image(coefficients)
.matrixMultiply(arrayImage2D)
.arrayProject([0])
.arrayFlatten(
[['brightness','greenness','wetness','forth','fifth','sixth']]);
print(componentImages);
Map.addLayer(componentImages,[],'TC',false);
Coefficients variable should be rewrite with ee.Array:
var coefficients = ee.Array([
[0.3029, 0.2786, 0.4733, 0.5599, 0.508, 0.1872],
[-0.2941, -0.243, -0.5424, 0.7276, 0.0713, -0.1608],
[0.1511, 0.1973, 0.3283, 0.3407, -0.7117, -0.4559],
[-0.8239, 0.0849, 0.4396, -0.058, 0.2013, -0.2773],
[-0.3294, 0.0557, 0.1056, 0.1855, -0.4349, 0.8085],
[0.1079, -0.9023, 0.4119, 0.0575, -0.0259, 0.0252]]);
Correct answer by AmirHossein Ahrari on February 14, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP