【问题标题】:Calculating the area of classified pixels in google earth engine在谷歌地球引擎中计算分类像素的面积
【发布时间】:2019-01-10 22:29:59
【问题描述】:

我的问题代码如下:

var image = ee.Image(sent2
 .filterBounds(geometry2)
 .filterDate('2016-01-01', '2016-03-31')
 .sort("CLOUD_COVERAGE_ASSESSMENT")
 .first());

// print the image to the console.

    print("A Sentinel-2 scene:", image);

裁剪研究区域的几何图形

var image1=image.clip(geometry2)

//merging the feature collection collected 

var newfc = forest.merge(gram2).merge(baresoil).merge(wheat2).merge(mustard2);

var bands = [ 'B8', 'B4', 'B3'];

var training = image1.select(bands).sampleRegions({collection: newfc, properties: ['landcover'], scale: 10});

使用 CART 训练分类器

var classifier = ee.Classifier.cart().train({features: training, classProperty: 'landcover', inputProperties: bands});

运行分类

var classified = image1.select(bands).classify(classifier);

Map.addLayer(classified, {min: 0, max: 4, palette: '0D5D07','B47610','F7C537','7CE72E','EFF60E']},'classification');

//0 森林 1 裸土 2 克 3 小麦 4 芥菜

var PIXEL_SCALE = 10; // Meters. Resolution of most sentinel bands

var PIXEL_AREA = PIXEL_SCALE * PIXEL_SCALE; // Square meters.

计算多边形中每个分类的像素数

var regionCoverHistogram = image1.select('classifier') .reduceRegion(ee.Reducer.frequencyHistogram(), geometry2, PIXEL_SCALE);

print('classified class pixel count within region', regionCoverHistogram);

var wheatPixelCount =ee.Dictionary(regionCoverHistogram.get('wheat2')).get(wheat2.toString());

var wheatArea = ee.Number(wheatPixelCount).multiply(PIXEL_AREA);

print('Wheat Area (sq meters) in region', wheatArea);

显示错误如下:

区域内分类的类像素数 字典(错误) Image.select:模式“分类器”不匹配任何波段。 地区小麦面积(平方米) 编号(错误) Image.select:模式“分类器”不匹配任何波段。

【问题讨论】:

    标签: google-earth-engine


    【解决方案1】:

    如果没有脚本,将很难分辨,但我的猜测是,您尝试为直方图选择的波段('分类器)不在 image1 内,而是在结果图像内:'分类'。

    将 image1 更改为分类将是第一个建议。

    【讨论】:

      猜你喜欢
      • 2021-04-12
      • 1970-01-01
      • 2019-01-05
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 2013-12-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多