Earth Engine:映射 ee.ImageCollection returns 和 ee.FeatureCollection
Earth Engine: Mapping over an ee.ImageCollection returns an ee.FeatureCollection
我正在尝试使用以下脚本从 Sentinel-2 图像集合中删除带有云的图像:
// Remove images with clouds
var cloud_removal = function(image){
// save the quality assessment band QA60 as a variable
var cloud_mask = image.select('QA60');
// calculate the sum of the QA60-Band (because QA60 != 0 means cloud or cirrus presence)
var cloud_pixels = cloud_mask.reduceRegion( // reduceRegion computes a single object value pair out of an image
{reducer:ee.Reducer.sum(), // calculates the sum of all pixels..
geometry:aoi, // inside the specified geometry
scale:60}) // at this scale (matching the band resolution of the QA60 band)
.getNumber('QA60'); // extracts the values as a number
return ee.Algorithms.If(cloud_pixels.eq(0), image);
};
var s2_collection_noclouds = s2_collection_clipped.map(cloud_removal, true);
print('The clipped Sentinel-2 image collection without cloudy images: ', s2_collection_noclouds);
问题是输出 ("s2_collection_noclouds") 是 ee.FeatureCollection。
我已经尝试将输出转换为图像集合,但它仍然是一个特征集合:
var s2_collection_noclouds = ee.ImageCollection(s2_collection_clipped.map(cloud_removal, true));
我错过了什么?
生成的对象确实是一个Image Collection,可以显示在地图上。例如:
var visualization = {
min: 0,
max: 3000,
bands: ['B4', 'B3', 'B2'],
};
Map.addLayer(s2_collection_noclouds.median(), visualization, "Sentinel-2")
旁注:我确实看到 Earth Engine 代码编辑器控制台将对象类型标记为“FeatureCollection”,并且该集合包含图像对象的特征。这似乎是因为映射函数 return 中的 ee.Algorithms.If() 是多云图像的空对象。如果您改为 return 蒙版图像:
return ee.Algorithms.If(cloud_pixels.eq(0), image, image.mask(0));
然后该集合被正确描述为 ImageCollection。
我正在尝试使用以下脚本从 Sentinel-2 图像集合中删除带有云的图像:
// Remove images with clouds
var cloud_removal = function(image){
// save the quality assessment band QA60 as a variable
var cloud_mask = image.select('QA60');
// calculate the sum of the QA60-Band (because QA60 != 0 means cloud or cirrus presence)
var cloud_pixels = cloud_mask.reduceRegion( // reduceRegion computes a single object value pair out of an image
{reducer:ee.Reducer.sum(), // calculates the sum of all pixels..
geometry:aoi, // inside the specified geometry
scale:60}) // at this scale (matching the band resolution of the QA60 band)
.getNumber('QA60'); // extracts the values as a number
return ee.Algorithms.If(cloud_pixels.eq(0), image);
};
var s2_collection_noclouds = s2_collection_clipped.map(cloud_removal, true);
print('The clipped Sentinel-2 image collection without cloudy images: ', s2_collection_noclouds);
问题是输出 ("s2_collection_noclouds") 是 ee.FeatureCollection。 我已经尝试将输出转换为图像集合,但它仍然是一个特征集合:
var s2_collection_noclouds = ee.ImageCollection(s2_collection_clipped.map(cloud_removal, true));
我错过了什么?
生成的对象确实是一个Image Collection,可以显示在地图上。例如:
var visualization = {
min: 0,
max: 3000,
bands: ['B4', 'B3', 'B2'],
};
Map.addLayer(s2_collection_noclouds.median(), visualization, "Sentinel-2")
旁注:我确实看到 Earth Engine 代码编辑器控制台将对象类型标记为“FeatureCollection”,并且该集合包含图像对象的特征。这似乎是因为映射函数 return 中的 ee.Algorithms.If() 是多云图像的空对象。如果您改为 return 蒙版图像:
return ee.Algorithms.If(cloud_pixels.eq(0), image, image.mask(0));
然后该集合被正确描述为 ImageCollection。