[null,null,["上次更新時間:2025-07-25 (世界標準時間)。"],[[["\u003cp\u003e\u003ccode\u003ereduceRegion\u003c/code\u003e calculates statistics of pixel values within a specified region of an \u003ccode\u003eee.Image\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe region can be a polygon or a single point, and the output is a statistic derived from the pixels within that region.\u003c/p\u003e\n"],["\u003cp\u003eA scale should always be specified in \u003ccode\u003ereduceRegion\u003c/code\u003e calls to ensure accurate results, either using the \u003ccode\u003escale\u003c/code\u003e parameter or by defining a CRS and CRS transform.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003emaxPixels\u003c/code\u003e parameter may need to be adjusted or \u003ccode\u003ebestEffort\u003c/code\u003e set to true to handle large regions and avoid computation errors.\u003c/p\u003e\n"],["\u003cp\u003ePixels are included in the calculation based on whether their centroid is within the region (unweighted reducers) or the fraction of the pixel covered by the region (weighted reducers), along with the image's mask.\u003c/p\u003e\n"]]],["`reduceRegion()` calculates statistics of pixel values within a specified region of an `ee.Image`. It uses a `Geometry` to define the region, which can range from a single point to a polygon. The key actions involve setting a `reducer` (e.g., `ee.Reducer.mean()`), `geometry`, `scale` or `crs`, and `maxPixels`. Pixel inclusion is determined by centroid location for unweighted reducers or pixel coverage for weighted ones, considering the image's mask. The output is a `Dictionary` of statistics derived from pixel values.\n"],null,["# Statistics of an Image Region\n\n`reduceRegion`\n--------------\n\nTo get statistics of pixel values in a region of an `ee.Image`, use\n[`image.reduceRegion()`](/earth-engine/apidocs/ee-image-reduceregion).\nThis reduces all the pixels in the region(s) to a\nstatistic or other compact representation of the pixel data in the region (e.g.\nhistogram). The region is represented as a `Geometry`, which might be a\npolygon, containing many pixels, or it might be a single point, in which case there will\nonly be one pixel in the region. In either case, as illustrated in Figure 1, the output\nis a statistic derived from the pixels in the region.\nFigure 1. An illustration of an `ee.Reducer` applied to an image and a region.\n\nFor an example of getting pixel statistics in a region of an image using\n`reduceRegion()`, consider finding the mean spectral\nvalues of a 5-year Landsat composite within the boundaries of the Sierra Nevada\nConiferous Forest (illustrated by Figure 2): \n\n```gdscript\n// Load input imagery: Landsat 7 5-year composite.\nvar image = ee.Image('LANDSAT/LE7_TOA_5YEAR/2008_2012');\n\n// Load an input region: Sierra Nevada.\nvar region = ee.Feature(ee.FeatureCollection('EPA/Ecoregions/2013/L3')\n .filter(ee.Filter.eq('us_l3name', 'Sierra Nevada'))\n .first());\n\n// Reduce the region. The region parameter is the Feature geometry.\nvar meanDictionary = image.reduceRegion({\n reducer: ee.Reducer.mean(),\n geometry: region.geometry(),\n scale: 30,\n maxPixels: 1e9\n});\n\n// The result is a Dictionary. Print it.\nprint(meanDictionary);\n```\n\nTo force the computation, it suffices to print the result, which the Code Editor will\ndisplay as a `Dictionary` in the console. The output should look something like: \n\n```\nB1: 25.406029716816853\nB2: 23.971497014238988\nB3: 22.91059593763103\nB4: 54.83164133293403\nB5: 38.07655472573677\nB6_VCID_2: 198.93216428012906\nB7: 24.063261634961563\n```\nFigure 2. False color composite of the Landsat image data for California and Nevada. The region over which to reduce is shown in white.\n\nNote that in this example the reduction is specified by providing the `reducer`\n(`ee.Reducer.mean()`), the `geometry` (`region.geometry()`),\nthe `scale` (30 meters) and `maxPixels` for the maximum number of\npixels to input to the reducer. A scale should always be specified in\n`reduceRegion()` calls. This is because in complex processing flows, which\nmay involve data from different sources with different scales, the scale of the output\nwill not be unambiguously determined from the inputs. In that case, the scale defaults\nto 1 degree, which generally produces unsatisfactory results. See [this\npage](/earth-engine/guides/scale) for more information about how Earth Engine handles scale.\n\nThere are two ways to set the scale: by specifying the `scale` parameter,\nor by specifying a CRS and CRS transform. (See [the glossary](/earth-engine/glossary) for\nmore information about CRS's and CRS transforms). For example, the\n`meanDictionary` reduction (above) is equivalent to the following: \n\n```gdscript\n// As an alternative to specifying scale, specify a CRS and a CRS transform.\n// Make this array by constructing a 4326 projection at 30 meters,\n// then copying the bounds of the composite, from composite.projection().\nvar affine = [0.00026949458523585647, 0, -180, 0, -0.00026949458523585647, 86.0000269494563];\n\n// Perform the reduction, print the result.\nprint(image.reduceRegion({\n reducer: ee.Reducer.mean(),\n geometry: region.geometry(),\n crs: 'EPSG:4326',\n crsTransform: affine,\n maxPixels: 1e9\n}));\n```\n\nIn general, specifying the scale is sufficient and results in more readable code.\nEarth Engine determines which pixels to input to the reducer by first rasterizing the region.\nIf a scale is specified without a CRS, the region is rasterized in the image's native\nprojection scaled to the specified resolution. If both a CRS and scale are specified, the\nregion is rasterized based on them.\n\nPixels in the region\n--------------------\n\nPixels are determined to be in the region (and weighted) according to the following rules,\napplied in the specified scale and projection:\n\n- **Unweighted reducers** (e.g. `ee.Reducer.count()` or `ee.Reducer.mean().unweighted()`): pixels are included if their centroid is in the region and the image's mask is non-zero.\n- **Weighted reducers** (e.g. `ee.Reducer.mean()`): pixels are included if at least (approximately) 0.5% of the pixel is in the region and the image's mask is non-zero; their weight is the minimum of the image's mask and the (approximate) fraction of the pixel covered by the region.\n\nThe `maxPixels` parameter is needed to get the computation to succeed. If this\nparameter is left out of the example, an error is returned, which looks something like:\n| Dictionary (Error) \n| Image.reduceRegion: Too many pixels in the region. Found 527001545, but only 10000000 allowed. \n\nThere are multiple options to get past these errors: increase `maxPixels`,\nas in the example, increase the `scale`, or set `bestEffort` to\ntrue, which automatically computes a new (larger) scale such that `maxPixels`\nis not exceeded. If you do not specify `maxPixels`, the default value is used."]]