Json 使用Google Earth引擎中图像集合中每个单独图像的标注栏中的值填充FeatureCollection

Json 使用Google Earth引擎中图像集合中每个单独图像的标注栏中的值填充FeatureCollection,json,google-earth-engine,Json,Google Earth Engine,在Google Earth引擎中,我将Featurecollection作为JSON加载,其中包含一些多边形。我想在这个FeatureCollection中添加一些列,它为我提供了每个多边形和图像集合中包含的多个图像的两个带的平均值 这是我到目前为止的代码 //Polygons var polygons = ee.FeatureCollection('ft:1_z8-9NMZnJie34pXG6l-3StxlcwSKSTJFfVbrdBA'); Map.addLayer(polygons);

在Google Earth引擎中,我将Featurecollection作为JSON加载,其中包含一些多边形。我想在这个FeatureCollection中添加一些列,它为我提供了每个多边形和图像集合中包含的多个图像的两个带的平均值

这是我到目前为止的代码

//Polygons

var polygons = ee.FeatureCollection('ft:1_z8-9NMZnJie34pXG6l-3StxlcwSKSTJFfVbrdBA');

Map.addLayer(polygons);

//Date of interest

var start = ee.Date('2008-01-01');
var finish = ee.Date('2010-12-31');

//IMPORT Landsat IMAGEs
var Landsat = ee.ImageCollection('LANDSAT/LT05/C01/T1') //Landsat images
.filterBounds(polygons)
.filterDate(start,finish)
.select('B4','B3');

//Add ImageCollection to Map
Map.addLayer(Landsat);

//Map the function over the collection and display the result
print(Landsat);

// Empty Collection to fill
var ft = ee.FeatureCollection(ee.List([]))

var fill = function(img, ini) {
  // type cast
  var inift = ee.FeatureCollection(ini)

  // gets the values for the points in the current img
  var mean = img.reduceRegions({
    collection:polygons,
    reducer: ee.Reducer.mean(),
 });

 // Print the first feature, to illustrate the result.
print(ee.Feature(mean.first()).select(img.bandNames()));

  // writes the mean in each feature
  var ft2 = polygons.map(function(f){return f.set("mean", mean)})

  // merges the FeatureCollections
  return inift.merge(ft2)

  // gets the date of the img
  var date = img.date().format()

  // writes the date in each feature
  var ft3 = polygons.map(function(f){return f.set("date", date)})

  // merges the FeatureCollections
  return inift.merge(ft3)
}

// Iterates over the ImageCollection
var newft = ee.FeatureCollection(Landsat.iterate(fill, ft))

// Export
Export.table.toDrive(newft,
"anyDescription",
"anyFolder",
"test")
在控制台中,我收到一条错误消息

元素(错误) 未能解码JSON。 错误:缺少对象“{”类型“:“ArgumentRef”,“value”:null}”的字段“value”或null。 对象:{“类型”:“ArgumentRef”,“值”:null}


在生成的csv文件中,我得到了一个名为mean的新列,但该列中填充了实际值,而没有实际值。

这里没有理由使用
iterate()
。您可以做的是嵌套的
map()
。在多边形上,然后在图像上。您可以将结果列表展平,将其转换为单个列表,如下所示:

//通过在多边形上映射,然后在图像上映射,计算平均频带值
var results=polygons.map(函数(f){
返回images.map(函数(i){
var平均值=i.还原区域({
几何体:f.几何体(),
减速器:ee.reducer.mean(),
});
返回f.setMulti(mean).set({date:i.date()})
})
})
//压扁
结果=结果。展平()
脚本:

同样的方法也可以用于
reduceRegions()
,在图像上映射,然后在区域上映射。但是,您必须映射生成的功能以设置日期

images.filterBounds(f)
如果您的功能覆盖更大的区域,可能还可以添加


PS:您的表格未共享

我知道这很难评论,但如果我需要为每个图像提取多个值,而不仅仅是日期,我该怎么办。例如,我需要为每个实例提取B1、B2和B3的值。有关更多详细信息,请参阅我的问题链接: