公告:所有在
2025 年 4 月 15 日之前注册使用 Earth Engine 的非商业项目都必须
验证是否符合非商业性质的资格条件,才能继续使用 Earth Engine。
ee.Image.pixelArea
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
生成一张图片,其中每个像素的值都是相应像素的面积(以平方米为单位)。返回的图片具有一个名为“area”的波段。
用法 | 返回 |
---|
ee.Image.pixelArea() | 图片 |
无实参。
示例
代码编辑器 (JavaScript)
// Create a pixel area image. Pixel values are square meters based on
// a given CRS and scale (or CRS transform).
var pixelArea = ee.Image.pixelArea();
// The default projection is WGS84 with 1-degree scale.
print('Pixel area default projection', pixelArea.projection());
// When inspecting the output in the Code Editor map, the scale of analysis is
// determined by the zoom level. As you zoom in and out, you'll notice that the
// area of the clicked pixel changes. To set a specific pixel scale when
// performing a computation, provide an argument to the `scale` or
// `crsTransform` parameters whenever a function gives you the option.
Map.addLayer(pixelArea, null, 'Pixel area for inspection', false);
// The "area" band produced by the `pixelArea` function can be useful for
// calculating the area of a certain condition of another image. For example,
// here we use the sum reducer to determine the area above 2250m in the North
// Cascades ecoregion, according to a 30m digital elevation model.
// Import a DEM and subset the "elevation" band.
var elev = ee.Image('NASA/NASADEM_HGT/001').select('elevation');
// Define a high elevation mask where pixels with elevation greater than 2250m
// are set to 1, otherwise 0.
var highElevMask = elev.gt(2250);
// Apply the high elevation mask to the pixel area image.
var highElevArea = pixelArea.updateMask(highElevMask);
// Import an ecoregion feature collection and filter it by ecoregion name.
var ecoregion = ee.FeatureCollection('RESOLVE/ECOREGIONS/2017')
.filter('ECO_NAME == "North Cascades conifer forests"');
// Display the ecoregion and high elevation area.
Map.setCenter(-121.127, 48.389, 7);
Map.addLayer(ecoregion, null, 'North Cascades ecoregion');
Map.addLayer(highElevArea.clip(ecoregion),
{palette: 'yellow'}, 'High elevation area');
// Sum the area of high elevation pixels in the North Cascades ecoregion.
var area = highElevArea.reduceRegion({
reducer: ee.Reducer.sum(),
geometry: ecoregion,
crs: elev.projection(), // DEM coordinate reference system
crsTransform: elev.projection().getInfo().transform, // DEM grid alignment
maxPixels: 1e8
});
// Fetch the summed area property from the resulting dictionary and convert
// square meters to square kilometers.
var squareMeters = area.getNumber('area');
var squareKilometers = squareMeters.divide(1e6);
print('Square meters above 2250m elevation', squareMeters);
print('Square kilometers above 2250m elevation', squareKilometers);
Python 设置
如需了解 Python API 和如何使用 geemap
进行交互式开发,请参阅
Python 环境页面。
import ee
import geemap.core as geemap
Colab (Python)
# Create a pixel area image. Pixel values are square meters based on
# a given CRS and scale (or CRS transform).
pixel_area = ee.Image.pixelArea()
# The default projection is WGS84 with 1-degree scale.
display('Pixel area default projection', pixel_area.projection())
# When inspecting the output in the Code Editor map, the scale of analysis is
# determined by the zoom level. As you zoom in and out, you'll notice that the
# area of the clicked pixel changes. To set a specific pixel scale when
# performing a computation, provide an argument to the `scale` or
# `crsTransform` parameters whenever a function gives you the option.
m = geemap.Map()
m.add_layer(pixel_area, None, 'Pixel area for inspection', False)
# The "area" band produced by the `pixel_area` function can be useful for
# calculating the area of a certain condition of another image. For example,
# here we use the sum reducer to determine the area above 2250m in the North
# Cascades ecoregion, according to a 30m digital elevation model.
# Import a DEM and subset the "elevation" band.
elev = ee.Image('NASA/NASADEM_HGT/001').select('elevation')
# Define a high elevation mask where pixels with elevation greater than 2250m
# are set to 1, otherwise 0.
high_elev_mask = elev.gt(2250)
# Apply the high elevation mask to the pixel area image.
high_elev_area = pixel_area.updateMask(high_elev_mask)
# Import an ecoregion feature collection and filter it by ecoregion name.
ecoregion = ee.FeatureCollection('RESOLVE/ECOREGIONS/2017').filter(
'ECO_NAME == "North Cascades conifer forests"'
)
# Display the ecoregion and high elevation area.
m.set_center(-121.127, 48.389, 7)
m.add_layer(ecoregion, None, 'North Cascades ecoregion')
m.add_layer(
high_elev_area.clip(ecoregion), {'palette': 'yellow'}, 'High elevation area'
)
display(m)
# Sum the area of high elevation pixels in the North Cascades ecoregion.
area = high_elev_area.reduceRegion(
reducer=ee.Reducer.sum(),
geometry=ecoregion,
crs=elev.projection(), # DEM coordinate reference system
crsTransform=elev.projection().getInfo()['transform'], # DEM grid alignment
maxPixels=1e8,
)
# Fetch the summed area property from the resulting dictionary and convert
# square meters to square kilometers.
square_meters = area.getNumber('area')
square_kilometers = square_meters.divide(1e6)
display('Square meters above 2250m elevation', square_meters)
display('Square kilometers above 2250m elevation', square_kilometers)
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003e\u003ccode\u003eee.Image.pixelArea()\u003c/code\u003e generates an image where each pixel value represents its area in square meters.\u003c/p\u003e\n"],["\u003cp\u003eThe output image has a single band named "area" and can be used to calculate areas based on conditions applied to other images.\u003c/p\u003e\n"],["\u003cp\u003eBy default, the projection is WGS84 with a 1-degree scale; however, custom scales and projections can be used.\u003c/p\u003e\n"],["\u003cp\u003eThis function is useful for calculating the area of specific regions or features that meet defined criteria, such as calculating the total area above a certain elevation within a specific geographic boundary.\u003c/p\u003e\n"]]],[],null,["# ee.Image.pixelArea\n\nGenerate an image in which the value of each pixel is the area of that pixel in square meters. The returned image has a single band called \"area.\"\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|------------------------|---------|\n| `ee.Image.pixelArea()` | Image |\n\n**No arguments.**\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// Create a pixel area image. Pixel values are square meters based on\n// a given CRS and scale (or CRS transform).\nvar pixelArea = ee.Image.pixelArea();\n\n// The default projection is WGS84 with 1-degree scale.\nprint('Pixel area default projection', pixelArea.projection());\n\n// When inspecting the output in the Code Editor map, the scale of analysis is\n// determined by the zoom level. As you zoom in and out, you'll notice that the\n// area of the clicked pixel changes. To set a specific pixel scale when\n// performing a computation, provide an argument to the `scale` or\n// `crsTransform` parameters whenever a function gives you the option.\nMap.addLayer(pixelArea, null, 'Pixel area for inspection', false);\n\n// The \"area\" band produced by the `pixelArea` function can be useful for\n// calculating the area of a certain condition of another image. For example,\n// here we use the sum reducer to determine the area above 2250m in the North\n// Cascades ecoregion, according to a 30m digital elevation model.\n\n// Import a DEM and subset the \"elevation\" band.\nvar elev = ee.Image('NASA/NASADEM_HGT/001').select('elevation');\n\n// Define a high elevation mask where pixels with elevation greater than 2250m\n// are set to 1, otherwise 0.\nvar highElevMask = elev.gt(2250);\n\n// Apply the high elevation mask to the pixel area image.\nvar highElevArea = pixelArea.updateMask(highElevMask);\n\n// Import an ecoregion feature collection and filter it by ecoregion name.\nvar ecoregion = ee.FeatureCollection('RESOLVE/ECOREGIONS/2017')\n .filter('ECO_NAME == \"North Cascades conifer forests\"');\n\n// Display the ecoregion and high elevation area.\nMap.setCenter(-121.127, 48.389, 7);\nMap.addLayer(ecoregion, null, 'North Cascades ecoregion');\nMap.addLayer(highElevArea.clip(ecoregion),\n {palette: 'yellow'}, 'High elevation area');\n\n// Sum the area of high elevation pixels in the North Cascades ecoregion.\nvar area = highElevArea.reduceRegion({\n reducer: ee.Reducer.sum(),\n geometry: ecoregion,\n crs: elev.projection(), // DEM coordinate reference system\n crsTransform: elev.projection().getInfo().transform, // DEM grid alignment\n maxPixels: 1e8\n});\n\n// Fetch the summed area property from the resulting dictionary and convert\n// square meters to square kilometers.\nvar squareMeters = area.getNumber('area');\nvar squareKilometers = squareMeters.divide(1e6);\n\nprint('Square meters above 2250m elevation', squareMeters);\nprint('Square kilometers above 2250m elevation', squareKilometers);\n```\nPython setup\n\nSee the [Python Environment](/earth-engine/guides/python_install) page for information on the Python API and using\n`geemap` for interactive development. \n\n```python\nimport ee\nimport geemap.core as geemap\n```\n\n### Colab (Python)\n\n```python\n# Create a pixel area image. Pixel values are square meters based on\n# a given CRS and scale (or CRS transform).\npixel_area = ee.Image.pixelArea()\n\n# The default projection is WGS84 with 1-degree scale.\ndisplay('Pixel area default projection', pixel_area.projection())\n\n# When inspecting the output in the Code Editor map, the scale of analysis is\n# determined by the zoom level. As you zoom in and out, you'll notice that the\n# area of the clicked pixel changes. To set a specific pixel scale when\n# performing a computation, provide an argument to the `scale` or\n# `crsTransform` parameters whenever a function gives you the option.\nm = geemap.Map()\nm.add_layer(pixel_area, None, 'Pixel area for inspection', False)\n\n# The \"area\" band produced by the `pixel_area` function can be useful for\n# calculating the area of a certain condition of another image. For example,\n# here we use the sum reducer to determine the area above 2250m in the North\n# Cascades ecoregion, according to a 30m digital elevation model.\n\n# Import a DEM and subset the \"elevation\" band.\nelev = ee.Image('NASA/NASADEM_HGT/001').select('elevation')\n\n# Define a high elevation mask where pixels with elevation greater than 2250m\n# are set to 1, otherwise 0.\nhigh_elev_mask = elev.gt(2250)\n\n# Apply the high elevation mask to the pixel area image.\nhigh_elev_area = pixel_area.updateMask(high_elev_mask)\n\n# Import an ecoregion feature collection and filter it by ecoregion name.\necoregion = ee.FeatureCollection('RESOLVE/ECOREGIONS/2017').filter(\n 'ECO_NAME == \"North Cascades conifer forests\"'\n)\n\n# Display the ecoregion and high elevation area.\nm.set_center(-121.127, 48.389, 7)\nm.add_layer(ecoregion, None, 'North Cascades ecoregion')\nm.add_layer(\n high_elev_area.clip(ecoregion), {'palette': 'yellow'}, 'High elevation area'\n)\ndisplay(m)\n\n# Sum the area of high elevation pixels in the North Cascades ecoregion.\narea = high_elev_area.reduceRegion(\n reducer=ee.Reducer.sum(),\n geometry=ecoregion,\n crs=elev.projection(), # DEM coordinate reference system\n crsTransform=elev.projection().getInfo()['transform'], # DEM grid alignment\n maxPixels=1e8,\n)\n\n# Fetch the summed area property from the resulting dictionary and convert\n# square meters to square kilometers.\nsquare_meters = area.getNumber('area')\nsquare_kilometers = square_meters.divide(1e6)\n\ndisplay('Square meters above 2250m elevation', square_meters)\ndisplay('Square kilometers above 2250m elevation', square_kilometers)\n```"]]