我在写一篇关于冰川变化的论文。我在Landsat 8图像上做了一个有监督的分类,我想数一数每个类中有多少像素。顺便说一下,我想做个图表。
但是我错了,我的代码出错了。我尝试使用带有指定参数的ui.Chart.image.byClass()方法,但是is不起作用。
我的代码:
var img = ee.Image('LANDSAT/LC8_L1T_TOA/LC81940282016238LGN00') ;
// Add pseudocolor image
Map.addLayer(img, {bands: ['B6', 'B5', 'B4'] }, 'Pseudocolor image' ) ;
// Training points for classification - Point geometries
var points = [class1,class2,class3, class4, class5] ;
var trainingPoints = ee.FeatureCollection(points) ;
var training = img.sampleRegions(trainingPoints, ['class'] ,30) ;
var trained = ee.Classifier.minimumDistance().train(training, 'class' ) ;
var classified = img.classify(trained) ;
var palette = ['red','red', '#696969' , '#90EE90' , '#008000' ] ;
Map.addLayer(classified, {min: 0 , max : 5 , palette : palette }, 'L8
classified' ) ;
print(classified);
var options = {
lineWidth: 1,
pointSize: 2,
hAxis: {title: 'Classes'},
vAxis: {title: 'Num of pixels'},
title: 'Number of pixels in each class.'
};
var chart = ui.Chart.image.byClass({
image : classified ,
classBand : 'classification',
region : aletsch //<-- A previousy defined line type geometry
}).setOptions(options) ; 以及它所造成的错误:
Dictionary.get:字典不包含key: group。
是否有其他工具来计算每个类中的像素数?
发布于 2018-01-11 18:11:46
你所缺少的是一个可以聚合的乐队。地球引擎知道你想要使用“分类”来对结果进行分组,但却找不到任何其他波段来计数(或以某种方式进行求和或减少)。这里有一个选择:
var pixelChart = ui.Chart.image.byClass({
image: ee.Image(1).addBands(classified),
classBand: 'classification',
region: region,
scale: 30,
reducer: ee.Reducer.count()
}).setOptions(options);它计算1的恒定图像中的像素数。也许更好的选择是面积之和(以平方米为单位):
var areaChart = ui.Chart.image.byClass({
image: ee.Image.pixelArea().addBands(classified),
classBand: 'classification',
region: region,
scale: 30,
reducer: ee.Reducer.sum()
});https://stackoverflow.com/questions/48193501
复制相似问题