Earth Engine 推出了
非商业配额层级,以保护共享计算资源并确保为所有人提供可靠的性能。非商业项目默认使用 Community
层级,但您可以随时更改项目的层级。
Google uses AI technology to translate content into your preferred language. AI translations can contain errors.
ee.ImageCollection.toArrayPerBand
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
将多个图片串联成一个数组图片。
| 用法 | 返回 |
|---|
ImageCollection.toArrayPerBand(axis, dropMasked) | 图片 |
| 实参 | 类型 | 详细信息 |
|---|
this:collection | ImageCollection | 要串联的图片。系统会针对每个波段单独执行串联,因此所有图片在每个波段中都必须具有相同的维度和形状,但沿串联轴的长度除外。 |
axis | 整数,默认值:0 | 要沿其串联的轴;必须至少为 0,且至多为集合中任何波段的最小维度。 |
dropMasked | 布尔值,默认值:false | 如果为 false(默认值),则输出像素的掩码值是输入像素的掩码的最小值。如果计算边界框内集合中的任何图片在某个像素处被完全遮盖,则该输出像素将被遮盖。因此,每个未遮盖的输出像素数组的大小都相同。
如果为 true,则输出像素的掩码值是输入掩码的最大值。系统会忽略在该像素处被完全遮盖的图片,并且这些图片不会为输出数组贡献数据。因此,输出数组对于每个像素而言不一定具有相同的大小。 |
示例
代码编辑器 (JavaScript)
// A function to extract and print the array of a selected pixel.
function sampleArrayImage(arrImg) {
var point = ee.Geometry.Point([0, 0]);
return arrImg.sample(point, 1).first().get('b1');
}
// Define three single-band constant images with unified data types.
var img0 = ee.Image(0).byte().rename('b1');
var img1 = ee.Image(1).byte().rename('b1');
var img2 = ee.Image(2).byte().rename('b1');
// 1. Basic usage: concatenate fully valid images along axis 0.
var colSimple = ee.ImageCollection([img0, img1, img2]);
var arrayBasic = colSimple.toArrayPerBand();
print('Basic toArrayPerBand (pixel array):', sampleArrayImage(arrayBasic));
// Result: [0, 1, 2]
// 2. Masking behavior: introduce an image with a masked pixel.
// Update mask so img1 has no valid data at the sampled pixel.
var img1Masked = img1.updateMask(0);
var colMasked = ee.ImageCollection([img0, img1Masked, img2]);
// By default (dropMasked = false), if any input image is masked at a pixel,
// the output array is masked at that pixel. Since sampling a masked pixel
// returns no features, we inspect the output image's mask directly.
var arrayDefault = colMasked.toArrayPerBand();
print('Default masking behavior (pixel mask is 0):',
sampleArrayImage(arrayDefault.mask()));
// Result: 0
// With dropMasked = true, if any input image is masked at a specific pixel,
// its value is omitted from the output array at that pixel. As a result,
// array lengths can vary across different pixels.
var arrayDropped = colMasked.toArrayPerBand(0, true);
print('dropMasked=true (pixel array omits image-specific masked pixels):',
sampleArrayImage(arrayDropped));
// Result: [0, 2]
Python 设置
如需了解 Python API 和如何使用
geemap 进行交互式开发,请访问
Python 环境页面。
import ee
import geemap.core as geemap
Colab (Python)
# A function to extract and print the array of a selected pixel.
def sample_array_image(arr_img):
point = ee.Geometry.Point([0, 0])
return arr_img.sample(point, 1).first().get('b1')
# Define three single-band constant images with unified data types.
img0 = ee.Image(0).byte().rename('b1')
img1 = ee.Image(1).byte().rename('b1')
img2 = ee.Image(2).byte().rename('b1')
# 1. Basic usage: concatenate fully valid images along axis 0.
col_simple = ee.ImageCollection([img0, img1, img2])
array_basic = col_simple.toArrayPerBand()
display('Basic toArrayPerBand (pixel array):', sample_array_image(array_basic))
# Result: [0, 1, 2]
# 2. Masking behavior: introduce an image with a masked pixel.
# Update mask so img1 has no valid data at the sampled pixel.
img1_masked = img1.updateMask(0)
col_masked = ee.ImageCollection([img0, img1_masked, img2])
# By default (dropMasked = False), if any input image is masked at a pixel,
# the output array is masked at that pixel. Since sampling a masked pixel
# returns no features, we inspect the output image's mask directly.
array_default = col_masked.toArrayPerBand()
display(
'Default masking behavior (pixel mask is 0):',
sample_array_image(array_default.mask()),
)
# Result: 0
# With dropMasked = true, if any input image is masked at a specific pixel,
# its value is omitted from the output array at that pixel. As a result,
# array lengths can vary across different pixels.
array_dropped = col_masked.toArrayPerBand(0, True)
display(
'dropMasked=True (pixel array omits image-specific masked pixels):',
sample_array_image(array_dropped),
)
# Result: [0, 2]
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2026-05-31。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2026-05-31。"],[],[]]