我正在尝试复制此python脚本以计算功能集合(Get results in an Earth Engine python script)的NDVI均值。好像代码计算结果,但看不到结果。 这是代码:
import datetime
import ee
ee.Initialize()
#Feature collection
fc = ee.FeatureCollection("ft:1x290vohty0Wgdn5jL3RlpzryK7dfOPtG6yY213e0");
fc_filtered = fc.filter(ee.Filter.equals('NUM_DECS', 1))
#Image collection
Sentinel_collection = (ee.ImageCollection('COPERNICUS/S2')
.filterBounds(fc_filtered)
.filterDate(ee.Date('2017-01-01'),ee.Date('2017-08-01')))
def GetSeries(feature):
def NDVIcalc(img):
red = img.select('B4')
nir = img.select('B8')
ndvi = nir.subtract(red).divide(nir.add(red)).rename(['NDVI'])
return (feature
.set(ndvi.reduceRegion(ee.Reducer.mean(), feature.geometry(), 10))
.set('date', img.date().format("YYYYMMdd")))
series = Sentinel_collection.map(NDVIcalc)
list = series.reduceColumns(ee.Reducer.toList(2), ['date', 'NDVI']).get('list')
return feature.set(ee.Dictionary(ee.List(list).flatten()))
result = fc_filtered.map(GetSeries)
print(result.getInfo())
给我这个结果:
{'columns': {}, 'type': 'FeatureCollection', 'features': [], 'properties': {'name': 'kmltest', 'DocID': '1x290vohty0Wgdn5jL3RlpzryK7dfOPtG6yY213e0'}}
所以它看起来不像是出现了什么?
我还没试过下面包含以下内容:
# Get all possible dates.
dates = ee.List(Sentinel_collection.map(function(img) {
return ee.Feature(null, {'date': img.date().format("YYYYMMdd") })
}).aggregate_array('date'))
# Make a default value for every date.
header = ee.Feature(null, ee.Dictionary(dates, ee.List.repeat(-1, dates.size())))
output = header.merge(result)
ee.batch.Export.table.toDrive(...)
对于做错什么的任何建议?希望将结果放在要素集中或导出为列表。
答案 0 :(得分:0)
据我所知,您必须将结果导出到CSV驱动器表。所以在这一行之后:
public static string HighlightKeywords(this string input, string keywords)
{
if (input == String.Empty || keywords == String.Empty)
{
return input;
}
string[] words = keywords.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.ToLower()).ToArray();
string[] originalWords = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
input = string.Empty;
foreach (var word in originalWords.Select((value, i) => new { i, value }))
{
input += words.Contains(word.value.ToLower()) ? string.Format("<span class=\"highlight\">{0}</span>", word.value) : word.value;
if (originalWords.Length - 1 != word.i) input += " ";
}
return input;
}
你必须写下这个:
result = fc_filtered.map(GetSeries)
如果您想知道导出是否已完成,请使用以下方法进行检查:
task=ee.batch.Export.table.toDrive(collection=result,description='Name_csv_file', fileFormat='CSV')
task.start()