首页 > 解决方案 > Earth Engine 将特征属性添加到 ImageCollection

问题描述

在 GEE 中处理 ImageCollection 时,我的函数删除了 feature 属性system:time_start但离开了segmentStartTime. 这意味着我不能ui.Chart.image.series用来绘制数据。这真的很小,因为我在本地进行绘图。但是,我很好奇如何将具有唯一值的新特性属性添加到 ImageCollection。

正如您在下面的代码中看到的,我尝试使用 .set()。这没有用。任何指针?

var s1_collection = ee.ImageCollection('COPERNICUS/S1_GRD')
    .filterBounds(geometry)
    .filterDate('2020-01-29', '2020-09-1')
    .filter(ee.Filter.and(
      ee.Filter.listContains('transmitterReceiverPolarisation', 'VV'),
      ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'),
      ee.Filter.eq('instrumentMode', 'IW')
    ));
print(s1_collection);

var addVVVH = function(image) {
  start = image.get('segmentStartTime')
  var VVVH = image.select('VV').divide(image.select('VH')).rename('VVVH')
  .copyProperties(image)
  .set('system:time_start', start);
  return image.addBands(VVVH);
};

var s1_collection2 = s1_collection.map(addVVVH);              
print(s1_collection2);

/////////
var panel = ui.Panel();
panel.style().set('width', '300px');

var intro = ui.Panel([
  ui.Label({
    value: 'Two Chart Inspector',
    style: {fontSize: '20px', fontWeight: 'bold'}
  }),
  ui.Label('Click point.')
]);
panel.add(intro);

var lon = ui.Label();
var lat = ui.Label();
panel.add(ui.Panel([lon, lat], ui.Panel.Layout.flow('horizontal')));

Map.onClick(function(coords) {
  lon.setValue('lon: ' + coords.lon.toFixed(2)),
  lat.setValue('lat: ' + coords.lat.toFixed(2));
  var point = ee.Geometry.Point(coords.lon, coords.lat);
  
  // Create S1 VV/VH chart
  var sentinelVVChart = ui.Chart.image.series(s1_collection2.select('VVVH'), point)
    .setChartType('ScatterChart')
    .setOptions({
      title: 'Sentinel backscatter (VV/VH)',
      trendlines: {0: {
        color: 'CC0000'
      }},
      lineWidth: 1,
      pointSize: 3,
    });
  panel.widgets().set(1, sentinelVVChart);
  
});

Map.style().set('cursor', 'crosshair');

ui.root.insert(0, panel);

标签: javascriptgoogle-earth-engine

解决方案


你几乎是对的;需要在return声明之后设置日期。这是你的目标吗?

var s1_collection = ee.ImageCollection('COPERNICUS/S1_GRD')
    .filterBounds(geometry)
    .filterDate('2020-01-29', '2020-09-1')
    .filter(ee.Filter.and(
      ee.Filter.listContains('transmitterReceiverPolarisation', 'VV'),
      ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'),
      ee.Filter.eq('instrumentMode', 'IW')
    ));
print(s1_collection);

var addVVVH = function(image) {
  var VVVH = image.select('VV').divide(image.select('VH')).rename('VVVH')
  .copyProperties(image)
  return image.addBands(VVVH)
  .set({'system:time_start': image.get('segmentStartTime')});
};

s1_collection = s1_collection.map(addVVVH);              
print(s1_collection);

var chart = ui.Chart.image.series({
  imageCollection: s1_collection.select('VVVH'),
  region: geometry,
  reducer: ee.Reducer.mean(),
  scale: 10,
  xProperty: 'date'
})
print(chart)

推荐阅读