I'm new to GEE and I'm trying to do a machine learning supervised classification using random forest. it turns out that I made a code taking different parts of other codes and it works well for small areas, but when I try to apply it to a larger area it only works in a part of the area, I already reviewed the code and I can't find the error. Can someone help me? There is my code: https://code.earthengine.google.com/d2d80d91fac3f3dca413d1ba5c1209ae

function maskS2clouds(image) {
  var qa = image.select('QA60');

  // Bits 10 and 11 are clouds and cirrus, respectively.
  var cloudBitMask = 1 << 10;
  var cirrusBitMask = 1 << 11;

  // Both flags should be set to zero, indicating clear conditions.
  var mask = qa.bitwiseAnd(cloudBitMask).eq(0)

  return image.updateMask(mask).divide(10000);

// Map the function over one month of data and take the median.
// Load Sentinel-2 TOA reflectance data.
var image = ee.ImageCollection('COPERNICUS/S2').filterBounds(studyarea)
                  .filterDate('2022-01-01', '2023-01-31')
                  // Pre-filter to get less cloudy granules.
                  .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))

var rgbVis = {
  min: 0.0,
  max: 0.3,
  bands: ['B5', 'B3', 'B2'],

Map.addLayer(image.median().clip(studyarea), rgbVis, 'RGB');

var image = ee.Image(image.first());

Map.addLayer(image,{min:0,max:3000,bands:"B4,B3,B2"}, "LT7");

// set the selection bands
var predictionBands = image.bandNames();
print (predictionBands);

var trainingData = vegetacao.merge(agua).merge(agro).merge(urban);

// sample the regions
var classifierTraining = image.select(predictionBands).sampleRegions(
                      {collection: trainingData, 
                        properties: ['land_class']

//train the classifier
var classifier =  ee.Classifier.smileRandomForest(10000).train({features:classifierTraining, 
                                                  inputProperties: predictionBands});

// get the classified image
var classified = image.select(predictionBands).classify(classifier).clip(studyarea);

var classifiedImage = image.classify(classifier).clip(studyarea);

var Palette = [
  '#1ffaff', //  vegetacao
  '#0da715', // agua
  '#bf04c2', // agro
  '#f6ff17', // urban

//add the classified image to the map
Map.addLayer(classified,  {min: 1, max: 4, palette: Palette}, "LULC");```
  • You have selected the first image from the image collection, which may not cover your study area. You can try doing image.median().
    – Padmanabha
    Apr 23 at 6:59
  • ithis error appears -> LULC: Tile error: Image.reduceRegions: The default WGS84 projection is invalid for aggregations. Specify a scale or crs & crs_transform. Apr 23 at 15:00
  • Need to set the scale property for sampleRegions
    – Padmanabha
    Apr 23 at 19:28


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.