var bands = ['B2', 'B3', 'B4', 'B5', 'B6', 'B7']; var imageCollection = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA') .filterBounds(roi) .filterDate('2017-01-01', '2017-08-01') .sort('CLOUD_COVER', false); var fillMissingValues = function(image) { var selected = image.select(bands).float(); var zeros = ee.Image.constant(0).toFloat(); var filled = zeros.blend(selected); return filled.select(bands); }; var filledCollection = imageCollection.map(fillMissingValues); // 从 filledCollection 中选择一幅图像用于生成随机点 var sampleImage = filledCollection.first(); // 从随机点生成器中获取随机点 var seed = 123; var randomPoints = ee.FeatureCollection.randomPoints({ region: roi, points: 150, seed: seed, tileScale: 16 }).map(function(feature) { // 为随机点添加类别属性 var classValue = ee.Number.parse(sampleImage.reduceRegion({ reducer: ee.Reducer.first(), geometry: feature.geometry(), scale: 30 }).values().get(0)).mod(60); return feature.set('classValue', 30); }); // 定义分类器并进行训练 var classifier = ee.Classifier.smileRandomForest(50, 100).train({ features: randomPoints, classProperty: 'classValue', inputProperties: bands // 使用 bands 变量作为输入属性 }); // 对整个图像进行分类 var classified = filledCollection.map(function(image){ return image.classify(classifier); }); // 将分类结果可视化 Map.addLayer(classified, {min: 0, max:100, palette: 'blue'}, 'Classification');报错Line 21: Unrecognized arguments (tileScale) to function: FeatureCollection.randomPoints(region, points, seed, maxError) Generates points that are uniformly random on the sphere, and within the given region. Args: region (Geometry): The region to generate points for. points (Integer, optional): The number of points to generate. seed (Long, optional): A seed for the random number generator. maxError (ErrorMargin, optional): The maximum amount of error tolerated when performing any necessary reprojection.
时间: 2024-01-30 08:03:23 浏览: 64
这个报错是因为 `ee.FeatureCollection.randomPoints()` 方法不支持 `tileScale` 参数,因此需要将其从参数列表中删除。最新的 `ee.FeatureCollection.randomPoints()` 方法只需要 3 个参数:`region`、`points` 和 `seed`。修改后的代码如下:
```
// 从 filledCollection 中选择一幅图像用于生成随机点
var sampleImage = filledCollection.first();
// 从随机点生成器中获取随机点
var seed = 123;
var randomPoints = ee.FeatureCollection.randomPoints({
region: roi,
points: 150,
seed: seed
}).map(function(feature) {
// 为随机点添加类别属性
var classValue = ee.Number.parse(sampleImage.reduceRegion({
reducer: ee.Reducer.first(),
geometry: feature.geometry(),
scale: 30
}).values().get(0)).mod(60);
return feature.set('classValue', 30);
});
// 定义分类器并进行训练
var classifier = ee.Classifier.smileRandomForest(50, 100).train({
features: randomPoints,
classProperty: 'classValue',
inputProperties: bands // 使用 bands 变量作为输入属性
});
// 对整个图像进行分类
var classified = filledCollection.map(function(image){
return image.classify(classifier);
});
// 将分类结果可视化
Map.addLayer(classified, {min: 0, max:100, palette: 'blue'}, 'Classification');
```
这样修改后,就可以正确地执行图像分类操作了。
阅读全文