這是一種方法。
在該腳本中,你得到一個字典沒有空值
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 14 11:21:09 2017
@author: Gennadii
"""
import ee
ee.Initialize()
geometry = ee.Geometry.Polygon([[[-71.54365539550781, -43.07340216393553],
[-71.5484619140625, -43.11050787253287],
[-71.488037109375, -43.125043167401266],
[-71.48460388183594, -43.0754084526532]]])
def calcMean(img):
# gets the mean NDVI for the area in this img
mean = img.reduceRegion(ee.Reducer.mean(), geometry, 30).get('NDVI')
# sets the date and the mean NDVI as a property of the image
return img.set('date', img.date().format()).set('mean', mean)
# Applies calcMean() in the collection
col = ee.ImageCollection("LANDSAT/LC8_L1T_8DAY_NDVI").filterDate("2014-01-01","2014-03-31").map(calcMean)
# Reduces the images properties to a list of lists
values = col.reduceColumns(ee.Reducer.toList(2), ['date', 'mean']).values().get(0)
# Type casts the result into a List
lista = ee.List(values)
# Converts the list of lists to a Dictionaty
means = ee.Dictionary(lista.flatten())
print "Dictionary of means:", means.getInfo()
,這等腳本,你也會得到空值。它們在這個腳本中被-10填充,但是您可以將其更改爲任何您需要的內容。它可能是0或字符串。
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 14 11:17:29 2017
@author: Rodrigo E. Principe
"""
import ee
ee.Initialize()
geometry = ee.Geometry.Polygon([[[-71.54365539550781, -43.07340216393553],
[-71.5484619140625, -43.11050787253287],
[-71.488037109375, -43.125043167401266],
[-71.48460388183594, -43.0754084526532]]])
col = ee.ImageCollection("LANDSAT/LC8_L1T_8DAY_NDVI").filterDate("2014-01-01","2014-03-31")
# Initial empty Dictionary
meansIni = ee.Dictionary()
def calcMean(img, first):
#gets the year of the image
year = img.date().format()
#gets the NDVI
nd = ee.Image(img).reduceRegion(ee.Reducer.mean(),geometry,30).get("NDVI")
#Checks for null values and fills them with whatever suits you (-10 is just an option)
ndvi = ee.Algorithms.If(ee.Algorithms.IsEqual(nd, None), -10, nd)
#fills the Dictionary
return ee.Dictionary(first).set(year, ndvi)
# Apply calcMean() to the collection
means = ee.Dictionary(col.iterate(calcMean, meansIni))
print "Dictionary of means:", means.getInfo()
因此,您需要一個列表,其中包含縮略圖在集合的每個圖像中的結果。是對的嗎?像[0.2,0.5,0.8,0.7]之類的東西? –
這是正確的。最好用某種方法將山谷與圖像聯繫起來。但我想我可以自己跟蹤訂單。 –