이전 섹션에서는 reduceRegion 메서드를 사용하여 관심 지역에서 손실된 총 산림 면적을 계산하는 방법을 알아봤습니다. 총 손실을 계산하는 대신 연도별 손실을 계산하는 것이 좋습니다. Earth Engine에서 이를 달성하는 방법은 그룹화된 리듀서를 사용하는 것입니다.
reduceRegion()의 출력을 그룹화하려면 정수 픽셀 값으로 그룹을 정의하는 그룹화 대역을 지정하면 됩니다. 다음 예에서는 이전 코드를 약간 수정하고 lossYear 밴드를 원본 이미지에 추가합니다. lossYear 밴드의 각 픽셀에는 손실이 발생한 연도를 나타내는 0~14 값이 포함됩니다. 또한 리듀서를 그룹화된 리듀서로 변경하여 그룹화된 밴드의 밴드 색인 (1)을 지정하므로 픽셀 영역이 lossYear 밴드의 값에 따라 합산되고 그룹화됩니다.
위의 코드를 실행하면 groups이라는 중첩 목록에 연간 산림 손실 면적이 출력됩니다. 결과를 사전으로 만들기 위해 출력을 약간 포맷할 수 있습니다. 연도를 키로, 손실 영역을 값으로 사용합니다. format() 메서드를 사용하여 연도 값을 0~14에서 2000~2014로 변환하고 있습니다.
[null,null,["최종 업데이트: 2025-07-26(UTC)"],[[["\u003cp\u003eThis tutorial demonstrates how to calculate yearly forest loss in a specific region using Google Earth Engine and grouped reducers.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003elossYear\u003c/code\u003e band is used to categorize forest loss by year, ranging from 2000 to 2014.\u003c/p\u003e\n"],["\u003cp\u003eThe output is formatted into a dictionary where years are keys and corresponding loss areas are values.\u003c/p\u003e\n"],["\u003cp\u003eA column chart is generated to visualize yearly forest loss trends using the \u003ccode\u003eui.Chart.array.values()\u003c/code\u003e method.\u003c/p\u003e\n"],["\u003cp\u003eThe tutorial further directs users to explore and compare with other deforestation monitoring datasets.\u003c/p\u003e\n"]]],["The content demonstrates how to calculate yearly forest loss using Earth Engine. It involves adding a `lossYear` band to an image, then using a grouped reducer (`reduceRegion`) to sum pixel areas based on the year of loss (0-14). The output is formatted into a dictionary with years (2000-2014) as keys and loss areas as values. Finally, `ui.Chart.array.values()` is used to create a column chart visualizing the yearly forest loss, with years on the x-axis and loss area on the y-axis.\n"],null,["# Charting Yearly Forest Loss\n\nCalculating Yearly Forest Loss\n------------------------------\n\nIn the previous section you learned how to\n[calculate total forest area lost](/earth-engine/tutorials/tutorial_forest_03#calculating-pixel-areas) in\nthe given region of interest using the `reduceRegion` method. Instead of\ncalculating the total loss, it would be helpful to compute the loss for each year. The way\nto achieve this in Earth Engine is using a [Grouped Reducer](/earth-engine/guides/reducers_grouping).\n\n\nTo group output of `reduceRegion()`, you can specify a grouping band that\ndefines groups by integer pixel values. In the following example, we slightly modify the\nprevious code and add the `lossYear` band to the original image. Each pixel in the\n`lossYear` band contain values from 0 to 14 - indicating the year in which the\nloss occurred. We also change the reducer to a grouped reducer, specifying the band index of\nthe grouping band (1) so the pixel areas will be summed and grouped according to the value\nin the `lossYear` band.\n\n### Code Editor (JavaScript)\n\n```javascript\n// Load country boundaries from LSIB.\nvar countries = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017');\n// Get a feature collection with just the Congo feature.\nvar congo = countries.filter(ee.Filter.eq('country_co', 'CF'));\n\n// Get the loss image.\n// This dataset is updated yearly, so we get the latest version.\nvar gfc2017 = ee.Image('UMD/hansen/global_forest_change_2017_v1_5');\nvar lossImage = gfc2017.select(['loss']);\nvar lossAreaImage = lossImage.multiply(ee.Image.pixelArea());\n\nvar lossYear = gfc2017.select(['lossyear']);\nvar lossByYear = lossAreaImage.addBands(lossYear).reduceRegion({\n reducer: ee.Reducer.sum().group({\n groupField: 1\n }),\n geometry: congo,\n scale: 30,\n maxPixels: 1e9\n});\nprint(lossByYear);\n```\n\nOnce you run the above code, you will see the yearly forest loss area printed out in a nested\nlist called `groups`. We can format the output a little to make the result a\ndictionary, with year as the key and loss area as the value. Notice that we are using the\n`format()` method to convert the year values from 0-14 to 2000-2014.\n\n### Code Editor (JavaScript)\n\n```javascript\nvar statsFormatted = ee.List(lossByYear.get('groups'))\n .map(function(el) {\n var d = ee.Dictionary(el);\n return [ee.Number(d.get('group')).format(\"20%02d\"), d.get('sum')];\n });\nvar statsDictionary = ee.Dictionary(statsFormatted.flatten());\nprint(statsDictionary);\n```\n\nMaking a chart\n--------------\n\nNow that we have yearly loss numbers, we are ready to prepare a chart. We will use the\n`ui.Chart.array.values()` method. This method takes an array (or list) of input\nvalues and an array (or list) of labels for the X-axis.\n\n\n### Code Editor (JavaScript)\n\n```javascript\nvar chart = ui.Chart.array.values({\n array: statsDictionary.values(),\n axis: 0,\n xLabels: statsDictionary.keys()\n}).setChartType('ColumnChart')\n .setOptions({\n title: 'Yearly Forest Loss',\n hAxis: {title: 'Year', format: '####'},\n vAxis: {title: 'Area (square meters)'},\n legend: { position: \"none\" },\n lineWidth: 1,\n pointSize: 3\n });\nprint(chart);\n```\n\nThe result should look like the chart below.\nFigure 1. Chart of Forest Loss by Year\n\nIn the [next section](/earth-engine/tutorials/tutorial_forest_04),\nyou'll learn about another deforestation monitoring dataset,\n[FORMA](https://www.cgdev.org/sites/default/files/1423248_file_Hammer_Kraft_Wheeler_FORMA_FINAL.pdf),\nand compare it to the Hansen et al. data."]]