我正在尝试从 Sentinel SR 图像执行有监督的土地覆盖分类并得到以下错误:
SR_2018.select(...).sampleRegions 不是函数
//import shapefile of study area
var boundary =ee.FeatureCollection(boundary);
Map.setCenter(43.4,5.5, 10)
/**
* Function to mask clouds using the Sentinel-2 QA band
* @param {ee.Image} image Sentinel-2 image
* @return {ee.Image} cloud masked Sentinel-2 image
*/
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)
.and(qa.bitwiseAnd(cirrusBitMask).eq(0));
return image.updateMask(mask).divide(10000);
}
//add an NDVI (Normalized Difference Vegetation Index) band to the images
var NDVI = function(image) {
// Add an NDVI band
return image.addBands(image.normalizedDifference(['B8', 'B4']).rename('NDVI'))
};
var dataset_SR = ee.ImageCollection('COPERNICUS/S2_SR')
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE',20))
.filterBounds(ee.FeatureCollection(boundary))
.map(function(image){return image.clip(boundary)})
.map(NDVI);
print(dataset_SR)
//create yearly median composites by using the available Sentinel SR data
//year 2018
var SR_2018 = dataset_SR
.filterDate('2018-12-01', '2018-12-31')
.map(maskS2clouds)
.map(NDVI);
var SR_2018_median = SR_2018
.reduce(ee.Reducer.median());
print(SR_2018_median)
//load the training data for the supervised classification
var trainingSites= urban.merge(water).merge(veg_high).merge(soil).merge(veg_med);
//Choose all the median bands available including the median NDVI band.
//Use only these bands for the prediction
var SR_bands = ['B2_median', 'B3_median', 'B4_median', 'B5_median', 'B6_median','B7_median','B8_median', 'B8A_median', 'B11_median', 'B12_median',
'TCI_R_median', 'TCI_G_median', 'TCI_B_median',
'NDVI_median'];
//print(image.getInfo());
// Get the values for all pixels in each polygon in the training.
var trainingData = SR_2018.select(SR_bands).sampleRegions({
collection: trainingSites, // Get the sample from the polygons FeatureCollection.
properties: ['landcover'], //Keep this list of properties from the polygons.
scale: 10
});
// Get a randomForest classifier and train it- with the training data.
var classifier_Train = ee.Classifier.randomForest(10).train({
features: trainingData,
classProperty: 'landcover',
inputProperties: SR_bands //bands
});
我尝试按照这篇文章 https://stackoverflow.com/questions/63984413/image-selectbands-sampleregions-is-not-a-function-error-what-must-i-do 中的建议使用 .toBands() 但确实如此不解决问题。