2017-12-08 8 views
0

Google 어스 엔진에서 몇 가지 다각형이 포함 된 JSON으로 Featurecollection을로드했습니다. 이 FeatureCollection에 열을 추가하여 각 다각형과 이미지 컬렉션에 포함 된 여러 이미지 각각에 대한 평균값을 제공합니다.Google 어스 엔진의 이미지 컬렉션에있는 개별 이미지의 각 밴드의 값으로 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을 디코딩 할 수 없습니다 (오류) 를 얻을. 오류 : '{ "type": "ArgumentRef", "value": null}'개체의 'value'필드가 없거나 null입니다. 개체 : { "type": "ArgumentRef", "value": null}.

생성 된 내 CSV 파일에서 평균이라는 새 열을 얻지 만이 값은 실제 값이없는 채워집니다.

답변

0

여기서 iterate()을 사용할 이유가 없습니다. 할 수있는 일은 중첩 된 map()입니다. 다각형 위에 그리고 나서 이미지 위에. 이 같은 하나의리스트에 설정하는 목록의 결과 목록을 평평하게 할 수 있습니다

// compute mean band values by mapping over polygons and then over images 
var results = polygons.map(function(f) { 
    return images.map(function(i) { 
    var mean = i.reduceRegion({ 
     geometry: f.geometry(), 
     reducer: ee.Reducer.mean(), 
    }); 

    return f.setMulti(mean).set({date: i.date()}) 
    }) 
}) 

// flatten 
results = results.flatten() 

스크립트 : 같은 접근 방식은 매핑 이미지를 통해 다음뿐만 아니라 reduceRegions() 사용할 수 있습니다 https://code.earthengine.google.com/b65a731c78f78a6f9e08300dcf552dff

지역 이상. 그러나 날짜를 설정하려면 결과 피쳐를 매핑해야합니다.

images.filterBounds(f) 또한 기능이 더 넓은 영역을 포함하는 경우 추가 될 수 있습니다.

추신 : 귀하의 테이블이 공유되지 않습니다