I want make Supervised Classification for all images in imagecollection. I make one image with all bands, but i can't make classification, console give error:

merged.sampleRegions is not a function

Maybe there's another way how to convert image collection to image with bands or what am I doing wrong ?

//there's my imagecollection with param
var imgcollection = ee.ImageCollection('COPERNICUS/S2')
  .filterDate('2017-01-05', '2018-01-05')
  .filter(ee.Filter.lt('CLOUD_COVERAGE_ASSESSMENT', 20));

//there's i make function which convert imagecollection to one image with bands
var mergeBands = function(image, previous) {
  return ee.Image(previous).addBands(image, ['B8', 'B4', 'B3','B2']);
//there i get one images with bands:8,4,3,2
var merged = imgcollection.iterate(mergeBands, ee.Image([]));

var newft = ee.FeatureCollection('ft:1k5OiHRqWMQ61dDqzVFVadbEB9T4DWp0_ppYPAl7X');

//there's i trying to classificate
var training = merged.sampleRegions({
  collection: newft,
  properties: ['Number'],
  scale: 30,
  • 1
    try casting merged: var merged = ee.Image(imgcollection.iterate(mergeBands, ee.Image([]))); – Rodrigo E. Principe Jul 12 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.