0

I am trying to conduct a lulc classification on google earth engine using landsat5 data for 2000, but every time it is showing me the error:

image.select(bands).sampleRegions is not a function

var shp = ee.FeatureCollection(mws)

 Map.addLayer(shp, {}, 'My Polygon')

 var pol = ee.FeatureCollection(poly2000)

 Map.addLayer(pol, {} )


  //landcover for 2000//
   var dataset = ee.ImageCollection("LANDSAT/LT05/C01/T1_TOA")
              .filterBounds(roi1)
              .filterDate('2000-01-01', '2000-01-31')
              .map(function(image){return image.clip(mws)});
              
            
            
    var trueColor432 = dataset.select(['B4', 'B3', 'B2']);
    var trueColor432Vis = {};
    Map.setCenter(88.41713038056656,26.861987108179317);
    Map.addLayer(trueColor432, trueColor432Vis, 'True Color (432)'); 

   var image = trueColor432;


   // merging sample points together
   var landcover = forest.merge(water).merge(clearing).merge(built_up);
       print(landcover);


     // selecting bands
     var bands= ['B2','B3','B4'];

    //sampling the input imagery to get a featurecollection of a training data

    var training = image.select(bands).sampleRegions({
        collection: landcover,
        properties: ['landcover'],
         scale: 30
    });


   //training the classifier
   var classifier= ee.Classifier.svm().train({
        features: training,
        classProperty : 'landcover',
        inputProperties: bands
   });

  //classifying the input imagery
  var classified= image.select(bands).classify(classifier);
Ryan M
  • 18,333
  • 31
  • 67
  • 74

1 Answers1

0

sampleRegions samples the pixels of an image: https://developers.google.com/earth-engine/apidocs/ee-image-sampleregions

Maybe adding .toBands() works?

var training = image.toBands().select(bands).sampleRegions({
    collection: landcover,
    properties: ['landcover'],
     scale: 30
});
  • Please don't write answers in a way that makes them look like questions. There are systems in place to check for Not An Answer (NAA) posts. This answer was falsely picked up by one of them. Please consider editing it to look more like an answer. Rephrase "Maybe adding .toBands() works?". – Sabito stands with Ukraine Nov 11 '20 at 13:08