【问题标题】:Google Earth Engine: Flatten a one-band ImageCollection into a multi-band single ImageGoogle Earth Engine:将单波段 ImageCollection 展平为多波段单图像
【发布时间】:2018-05-01 00:14:24
【问题描述】:

我想使用监督分类对具有明确时间模式的模式进行分类。例如,识别针叶林中的落叶乔木林分。 NDVI 会随着时间的推移在落叶林中以应易于检测的规则模式变化。我假设有一种简单的方法可以将时间数据集展平为单个图像,以便可以在分类算法中使用该图像中的波段。也许使用.map(....)

以下是一些构建答案的代码:

var startDate = '2016-05-01';
var endDate = '2016-09-01';

var lng = -122.3424; var lat = 37.9344; //SF
var region = ee.Geometry.Point(lng, lat);

//Image Import
var l8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
.filterBounds(region)
.filterDate(startDate,endDate);

// NDVI temporal
var ndvi = l8.map(function(image) {
  var ndvi = image.normalizedDifference(['B5', 'B4']).rename("NDVI");
  return ndvi;
  });

Map.addLayer(ndvi,{},"NDVI Temporal"); // 8 images with 1 band

//NDVI FLATTENED??????? I want 1 image with 8 bands. The below code doesn't work...
var ndviFlat = ee.Image().addBands(ndvi.map(function(image){
  var temp = image.select("NDVI");  
  return temp;
  }));

从那里,我会将 ndviFlat 传递给 .sampleRegions,它只适用于 Images 而不是 ImageCollections

//Classification Model:
var points = ee.FeatureCollection([trainingPointsPos,trainingPointsNeg]).flatten(); 

var training = ndviFlat.sampleRegions({
  collection: points,
  properties: ['class'],
  scale: 30
});

var trained = ee.Classifier.randomForest(20).train(training, 'class', bands);
classified = regLayers.select(bands).classify(trained);

【问题讨论】:

    标签: google-earth-engine


    【解决方案1】:

    这是一种方法:

    var startDate = '2016-05-01';
    var endDate = '2016-09-01';
    
    var lng = -122.3424; 
    var lat = 37.9344; //SF
    var region = ee.Geometry.Point(lng, lat);
    
    //Image Import
    var l8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
      .filterBounds(region)
      .filterDate(startDate, endDate);
    
    var empty = ee.Image();
    
    // NDVI temporal
    var ndvi = ee.Image(l8.iterate(function(image, previous) {
      var name = ee.String('NDVI_').cat(image.id());
      var ndvi = image.normalizedDifference(['B5', 'B4']).rename(name);
      return ee.Image(previous).addBands(ndvi);
    }, empty));
    
    // Remove the annoying non-band
    ndvi = ndvi.select(ndvi.bandNames().remove('constant'));
    
    Map.centerObject(region, 13);
    Map.addLayer(ndvi, {}, 'ndvi');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-21
      • 2019-03-29
      • 2023-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-06
      • 2015-06-16
      相关资源
      最近更新 更多