The Geo-ICT Blog

Tutorials/Post – ICT, GIS, Remote Sensing, Earth System, Humanitarian, Disaster Management, Travel

Area Calculation using Google Earth Engine

There are a couple of ways to calculate the area of the image in the Google Earth Engine. The full implementation of both method can be accessed using this link.

  1. Pixel Count Method
    We can calculate the area of the image by counting the total number of unmasked pixels in that image. Then, multiply the total number of unmasked pixels by the scale factor to get the area in square meters. An implementation for this is shown below.

    var countries = ee.FeatureCollection('ft:1tdSwUL7MVpOauSgRzqVTOwdfy17KDbw-1d9omPw');
    var Nepal = countries.filterMetadata('Country', 'equals', 'Nepal');
    
    var testAreaImage = ee.Image(1).clip(Nepal);
    var scaleforTestArea = 30;
    
    var reducer = testAreaImage.reduceRegion({
      reducer: ee.Reducer.sum(),
      geometry: Nepal,
      crs: 'EPSG:32645', // WGS Zone N 45
      scale: scaleforTestArea,
      maxPixels: 1E13
    });
    // km square
    var area = ee.Number(reducer.get('constant')).multiply(scaleforTestArea).multiply(scaleforTestArea).divide(1000000);
    // gives an area of 147502.63 km2
    print('area of Nepal using pixel count method: ', area.getInfo() + ' km2');
    
  2. Pixel Area Method (Recommended)
    The other method to calculate the area in the Google Earth Engine is to calculate the area of each unmasked pixel. Then, get the sum of all the pixel areas to calculate the area of the image. An implementation for the same area as above is shown below. Clearly, one can see that the second method works better than the first method.

    var countries = ee.FeatureCollection('ft:1tdSwUL7MVpOauSgRzqVTOwdfy17KDbw-1d9omPw');
    var Nepal = countries.filterMetadata('Country', 'equals', 'Nepal');
    var scaleforTestArea = 30;
    
    // km square
    var img = ee.Image.pixelArea().divide(1000000);
    
    var area2 = img.reduceRegion({
      reducer: ee.Reducer.sum(),
      geometry: Nepal,
      crs: 'EPSG:32645', // WGS Zone N 45
      scale: scaleforTestArea,
      maxPixels: 1E13
    });
    // gives an area of 147134.49 km2
    print('area of Nepal using pixel area method: ', ee.Number(area2.get('area')).getInfo() + ' km2');
    

Previous

Machine Learning and Artificial Intelligence Exploring the Google TensorFlow Ecosystem

Next

Connected Pixel Counts in Google Earth Engine

3 Comments

  1. omer

    Dear sir,

    This is very informative. I didnt understand why u divide it by 1000000.

    • biplovbhandari

      To convert it to km2.

      • omer

        Dear Biplovbhandari sir,
        i want to calculate the ndvi area, can u please check my code, i got error.

        var dataset = ee.Image(‘MODIS/MCD43A4_006_NDVI/2018_05_14’);
        var colorized=dataset.select(‘NDVI’).clip(SA);
        var scale = 30;
        var colorizedVis = {
        min: 0.0,
        max: 1.0,
        palette: [
        ‘FFFFFF’, ‘CE7E45’, ‘DF923D’, ‘F1B555’, ‘FCD163′, ’99B718′, ’74A901′,
        ’66A000’, ‘529400’, ‘3E8601’, ‘207401’, ‘056201’, ‘004C00’, ‘023B01’,
        ‘012E01’, ‘011D01’, ‘011301’
        ],
        };
        Map.setCenter(-7.03125, 31.0529339857, 2);
        Map.addLayer(colorized, colorizedVis, ‘Colorized’);
        var reducer = colorized.reduceRegion({
        reducer: ee.Reducer.sum(),
        geometry: SA,
        scale: 30,
        maxPixels: 1E13
        });
        // km square
        var area = ee.Number(reducer.get(‘SA’)).multiply(scale).multiply(scale).divide(1000000);
        // gives an area of 147502.63 km2
        print(‘area of Riyadh: ‘, area.getInfo() + ‘ km2’);

        error Is:
        Dictionary.get: Dictionary does not contain key: SA.

        please help me in this better.

        u can check this code on ur area of interest

Leave a Reply

Powered by WordPress & Theme by Anders Norén

%d bloggers like this: