2

I am trying to classify the India into forest, agriculture and urban areas using Google Earth Engine, but after classification I am trying to calculate areas of classes like this:

var im=l8.filterDate('2018-01-01','2018-12-31');
var cloudless =im.map(function(image) {
  var cloudy = ee.Algorithms.Landsat.simpleCloudScore(image).select('cloud');
  var mask = cloudy.lte(20)
  return image.updateMask(mask);
});
var cld=cloudless.median();
var cloud=cld.clipToCollection(ind);

do the classification:

var classNames=urban.merge(forest).merge(agriculture).merge(water);
var bands = ['B2', 'B3', 'B4', 'B5', 'B6', 'B7'];
var training = cloud.select(bands).sampleRegions({
 collection: classNames
properties: ['landcover'],
scale: 30
});
var classifier = ee.Classifier.randomForest().train({
 features: training,
 classProperty: 'landcover',
 inputProperties: bands
});
var classified = cloud.select(bands).classify(classifier);
Map.addLayer(classified,{min: 0, max: 3, palette: ['red', 'green', 'yellow','blue']},'classification');

Calculate the area of different classes

var names = ['urb','for','agri','watr']
var count = classified.eq([0,1,2,3]).rename(names);
var total = count.multiply(ee.Image.pixelArea());
var area = total.reduceRegion({
 reducer:ee.Reducer.sum(),
  geometry:ind,
  scale:30,
 maxPixels: 1e9,
 bestEffort:true
});
var area_pxa = ee.Number(area).divide(1e6)
print ('Area in (km²):', area_pxa)

When I am running this, it is taking a lot of time and showing error:

computation timed out.

How to overcome this error?

Here is the link to my code:https://code.earthengine.google.com/08783af235d2672177f2af9f1d81e714

1 Answer 1

1

The computation is too large (scale, extent, complexity, etc) to complete in the roughly 5 minutes that a request is allowed when working interactively in the Code Editor.

You could try to export your classification as an asset, before calculating the areas. Include something like this in your script:

Export.image.toAsset({
  image: classified,
  description: 'my_classification',
  scale: 30,
  pyramidingPolicy: {'.default': 'mode'}
})

Go to the "Tasks" section on the right hand side, and select 'Run'. Look at the docs for more details on how to do the export (https://developers.google.com/earth-engine/exporting). Once your task completes, you can import your classification and do further processing on it.

var classified = ee.Image('users/yourUserName/my_classification')
5
  • @Daniel, Hi. Could you explain how to implement your answer, so that a user interested in applying it can reproduce it? Jan 2, 2020 at 0:22
  • Hi,Daniel thanks for the reply.I am very new to Google Earth Engine,can you please explain little more how to implement this .
    – G.GAHAN
    Jan 2, 2020 at 4:21
  • I updated my answer with an example on how to export the classification. Jan 2, 2020 at 8:28
  • Also, please see the Use-Export section of the Developer Guide's Debugging page. Earth Engine tries to give you results in near-real-time in the browser, but for some operations, this is not possible and results in either timeout or computation too large messages. The browser is good for quickly checking a workflow. For instance, if you are trying to classify all of India, try setting the scale at 1000 or greater, just to see that the process worked. Then, do as Daniel suggests and export the result at 30 meters. Jan 2, 2020 at 17:35
  • when i am exporting the image classified,I am getting error:Request payload size exceeds the limit: 4194304 bytes.How to overcome this?
    – G.GAHAN
    Jan 7, 2020 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.