공지사항 :
2025년 4월 15일 전에 Earth Engine 사용을 위해 등록된 모든 비상업용 프로젝트는 액세스 권한을 유지하기 위해
비상업용 자격 요건을 인증 해야 합니다. 2025년 9월 26일까지 인증하지 않으면 액세스가 보류될 수 있습니다.
의견 보내기
ee.FeatureCollection.iterate
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
사용자가 제공한 함수를 컬렉션의 각 요소에 적용합니다. 사용자가 제공한 함수에는 두 개의 인수가 제공됩니다. 현재 요소와 이전 iterate() 호출에서 반환된 값 또는 첫 번째 반복의 경우 첫 번째 인수입니다. 결과는 사용자가 제공한 함수에 대한 최종 호출에서 반환된 값입니다.
Collection.iterate() 호출의 결과를 반환합니다.
사용 반환 값 FeatureCollection. iterate (algorithm, first )
ComputedObject
인수 유형 세부정보 다음과 같은 경우: collection
컬렉션 컬렉션 인스턴스입니다. algorithm
함수 각 요소에 적용할 함수입니다. 컬렉션의 요소와 이전 반복의 값을 두 개의 인수로 가져야 합니다. first
객체, 선택사항 초기 상태입니다.
예
코드 편집기 (JavaScript)
/**
* CAUTION: ee.FeatureCollection.iterate can be less efficient than alternative
* solutions implemented using ee.FeatureCollection.map or by converting feature
* properties to an ee.Array object and using ee.Array.slice and
* ee.Array.arrayAccum methods. Avoid ee.FeatureCollection.iterate if possible.
*/
// Monthly precipitation accumulation for 2020.
var climate = ee . ImageCollection ( 'IDAHO_EPSCOR/TERRACLIMATE' )
. filterDate ( '2020-01-01' , '2021-01-01' )
. select ( 'pr' );
// Region of interest: north central New Mexico, USA.
var roi = ee . Geometry . BBox ( - 107.19 , 35.27 , - 104.56 , 36.83 );
// A FeatureCollection of mean monthly precipitation accumulation for the
// region of interest.
var meanPrecipTs = climate . map ( function ( image ) {
var meanPrecip = image . reduceRegion (
{ reducer : ee . Reducer . mean (), geometry : roi , scale : 5000 });
return ee . Feature ( roi , meanPrecip )
. set ( 'system:time_start' , image . get ( 'system:time_start' ));
});
// A cumulative sum function to apply to each feature in the
// precipitation FeatureCollection. The first input is the current feature and
// the second is a list of features that accumulates at each step of the
// iteration. The function fetches the last feature in the feature list, gets
// the cumulative precipitation sum value from it, and adds it to the current
// feature's precipitation value. The new cumulative precipitation sum is set
// as a property of the current feature, which is appended to the feature list
// that is passed onto the next step of the iteration.
var cumsum = function ( currentFeature , featureList ) {
featureList = ee . List ( featureList );
var previousSum = ee . Feature ( featureList . get ( - 1 )). getNumber ( 'pr_cumsum' );
var currentVal = ee . Feature ( currentFeature ). getNumber ( 'pr' );
var currentSum = previousSum . add ( currentVal );
return featureList . add ( currentFeature . set ( 'pr_cumsum' , currentSum ));
};
// Use "iterate" to cumulatively sum monthly precipitation over the year with
// the above defined "cumsum" function. Note that the feature list used in the
// "cumsum" function is initialized as the "first" variable. It includes a
// temporary feature with the "pr_cumsum" property set to 0; this feature is
// filtered out of the final FeatureCollection.
var first = ee . List ([ ee . Feature ( null , { pr_cumsum : 0 , first : true })]);
var precipCumSum =
ee . FeatureCollection ( ee . List ( meanPrecipTs . iterate ( cumsum , first )))
. filter ( ee . Filter . notNull ([ 'pr' ]));
// Inspect the outputs.
print ( 'Note cumulative precipitation ("pr_cumsum") property' ,
precipCumSum );
print ( ui . Chart . feature . byFeature (
precipCumSum , 'system:time_start' , [ 'pr' , 'pr_cumsum' ]));
Python 설정
Python API 및 geemap
를 사용한 대화형 개발에 관한 자세한 내용은
Python 환경 페이지를 참고하세요.
import ee
import geemap.core as geemap
Colab (Python)
import altair as alt
# CAUTION: ee.FeatureCollection.iterate can be less efficient than alternative
# solutions implemented using ee.FeatureCollection.map or by converting feature
# properties to an ee.Array object and using ee.Array.slice and
# ee.Array.arrayAccum methods. Avoid ee.FeatureCollection.iterate if possible.
# Monthly precipitation accumulation for 2020.
climate = (
ee . ImageCollection ( 'IDAHO_EPSCOR/TERRACLIMATE' )
. filterDate ( '2020-01-01' , '2021-01-01' )
. select ( 'pr' )
)
# Region of interest: north central New Mexico, USA.
roi = ee . Geometry . BBox ( - 107.19 , 35.27 , - 104.56 , 36.83 )
# A FeatureCollection of mean monthly precipitation accumulation for the
# region of interest.
def mean_precip_ts_fun ( image ):
mean_precip = image . reduceRegion (
reducer = ee . Reducer . mean (), geometry = roi , scale = 5000
)
return ee . Feature ( roi , mean_precip ) . set (
'system:time_start' , image . get ( 'system:time_start' )
)
mean_precip_ts = climate . map ( mean_precip_ts_fun )
# A cumulative sum function to apply to each feature in the
# precipitation FeatureCollection. The first input is the current feature and
# the second is a list of features that accumulates at each step of the
# iteration. The function fetches the last feature in the feature list, gets
# the cumulative precipitation sum value from it, and adds it to the current
# feature's precipitation value. The new cumulative precipitation sum is set
# as a property of the current feature, which is appended to the feature list
# that is passed onto the next step of the iteration.
def cumsum ( current_feature , feature_list ):
feature_list = ee . List ( feature_list )
previous_sum = ee . Feature ( feature_list . get ( - 1 )) . getNumber ( 'pr_cumsum' )
current_val = ee . Feature ( current_feature ) . getNumber ( 'pr' )
current_sum = previous_sum . add ( current_val )
return feature_list . add ( current_feature . set ( 'pr_cumsum' , current_sum ))
# Use "iterate" to cumulatively sum monthly precipitation over the year with
# the above defined "cumsum" function. Note that the feature list used in the
# "cumsum" function is initialized as the "first" variable. It includes a
# temporary feature with the "pr_cumsum" property set to 0 this feature is
# filtered out of the final FeatureCollection.
first = ee . List ([ ee . Feature ( None , { 'pr_cumsum' : 0 , 'first' : True })])
precip_cum_sum = ee . FeatureCollection (
ee . List ( mean_precip_ts . iterate ( cumsum , first ))
) . filter ( ee . Filter . notNull ([ 'pr' ]))
precip_cum_sum = precip_cum_sum . map (
lambda feature : feature . set (
'date' ,
ee . Date ( feature . getNumber ( 'system:time_start' )) . format ( 'YYYY-MM-dd' ),
)
)
# Inspect the outputs.
display ( 'Note cumulative precipitation ("pr_cumsum") property' , precip_cum_sum )
df = geemap . ee_to_df ( precip_cum_sum , [ 'date' , 'pr' , 'pr_cumsum' ])
display ( df )
chart = (
alt . Chart ( df )
. mark_line ()
. encode ( x = 'date:T' , y = 'pr:Q' , color = alt . value ( 'blue' ))
)
chart += (
alt . Chart ( df )
. mark_line ()
. encode ( x = 'date:T' , y = 'pr_cumsum:Q' , color = alt . value ( 'red' ))
)
chart
의견 보내기
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스 에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스 에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책 을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-07-26(UTC)
의견을 전달하고 싶나요?
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-26(UTC)"],[],[]]