Announcement: All noncommercial projects registered to use Earth Engine before April 15, 2025 must verify noncommercial eligibility to maintain Earth Engine access.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-10-06 UTC."],[[["\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,["Generate 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\nCode 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\nColab (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```"]]