我有一个FeatureCollection,由许多(100-200)多边形('ftr_polygons')组成。我还有一个ImageCollection,它由Landsat8波段的中位数月度指标和指数(“ byMonth”)组成。我想要ReduceRegions并保存FeatureCollection中每个多边形的中值(或均值)空间平均值。最终目标是将多年(2013-2019年)每个多边形内每月平均带/指数的时间序列导出到csv。
使用下面的代码,我可以执行大约1年,但不仅如此,还会收到错误消息:“ FeatureCollection(错误)计算超时”。有更好的方法吗?
// define the function that will grab median (or mean) spatial reductions for each polygon, for each month
var extractdata = function(medianImage,ftr_polygons) {
var date_start = ee.Date(medianImage.get('system:time_start')).format("YYYY-MM"); // get date as string to append to each property
// spatial MEDIAN
ftr_polygons = medianImage.reduceRegions({ // create feature collection with new properties, bands for each month, uniquely named
collection: ftr_polygons,
reducer: ee.Reducer.median(),
scale: 30,
tileScale: 1}); // tile scale
var ftr_polygons_propnames = ftr_polygons.first().propertyNames(); // get property names first
var ftr_polygons_newnames = ftr_polygons_propnames.replace('NDVI_median',
ee.String('NDVI_median_').cat(date_start)); //replace property names with band+date
ftr_polygons_newnames = ftr_polygons_newnames.replace('EVI_median',
ee.String('EVI_median_').cat(date_start)); //replace property names with band+date
ftr_polygons_newnames = ftr_polygons_newnames.replace('NIRv_median',
ee.String('NIRv_median_').cat(date_start)) ; //replace property names with band+date
ftr_polygons = ftr_polygons.map(function(f) {return f.select(ftr_polygons_propnames,ftr_polygons_newnames)});
return ftr_polygons;
};
// apply the function over ImageCollection byMonth, beginning with feature collection ftr_polygons
var ftr_polygons = ee.FeatureCollection(byMonth.iterate(extractdata,ftr_polygons));
// remove geometry on each feature before printing or exporting
var myproperties=function(feature){
feature=ee.Feature(feature).setGeometry(null);
return feature;
};
var ftr_polygon_export = ftr_polygon.map(myproperties)
print(ftr_polygon_export.limit(1), 'For export w monthly properties');
也许这个答案:https://stackoverflow.com/a/48412324/12393507暗示了一种更好的方法:
相同的方法也可以与reduceRegions()一起使用,先映射到图像,然后映射到区域。但是,您将必须在生成的功能上进行映射才能设置日期。
我希望了解有关此方法的更多信息。
谢谢。