Google地球引擎:将单频段ImageCollection展平为多频段单张图像

时间:2018-04-27 19:24:43

标签: google-earth-engine

我想使用监督分类来对具有清晰时间模式的模式进行分类。例如,识别针叶林中落叶树的林分。 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);

1 个答案:

答案 0 :(得分: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');