0

I use supervised classification on the GEE platform, but now there is a problem:

classified: Layer error: Image.sampleRegions: Invalid numInputs: 0

Here is my code:

var trainingPoints = water.merge(vegetation).merge(bareland).merge(residential).merge(crop).merge(road);

// Read vector
var cy = ee.FeatureCollection("users/1458265615/cy");

// Display the table.
Map.addLayer(cy, {min: 0, max: 3000}, 'chaoyang');
Map.setCenter(110,19,5);
// Read Sentinel images
var S2 = ee.ImageCollection('COPERNICUS/S2');

// SYNTHESIS OF BEST-QUALITY IMAGE
function addNdvi(img)
{ 
  var ndvi = img.normalizedDifference (['B8','B3']).rename('ndvi'); 
  return img.addBands(ndvi); 
} 

// Set Parameters
var VIS_classes = 
{
  min: 1, 
  max: 6, 
  palette: ['#ffbc84','#86ff2c', '#3964ff','#1fc90b','#dbdae2','#270800']
};

//xuanhuan time series data
var i;
var j=0;
var ndvi;

for(i=2016;i<=2018;i++)
{
  var begin_time=i.toString()+"-01-01";
  var end_time=i.toString()+"-12-31";
  var layername="image"+i.toString();
  j++;
  var classified="classified"+j.toString();

  var S2=S2.filterDate(begin_time,end_time)
   .filterBounds(cy);
  var S2ndvi=S2.map(addNdvi);
  var S2hq=S2ndvi.qualityMosaic('ndvi');
  var ncy = S2hq.clip(cy);
  var training = ncy.sampleRegions(trainingPoints, ['class'],30) ; 
  var trained = ee.Classifier.minimumDistance().train(training, 'class' ); 
  var classified =  ncy.classify(trained); 
  Map.addLayer(ncy, {min: 0, max: 3000}, 'image');
  Map.addLayer(classified, VIS_classes , 'classified' ) ; 
}

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.